General

function to string processing

Started by Leo Souza on .

Sign in or create an account to join the conversation.

7 posts

Topic starter
Hi all,

I have developed this funcion at topmost level to help with string processing

name: converteHex
parameter: car

decl val=car;

if(car == '0') val = 0x30;
if(car == 0) val = 0x30;
else if(car == '\') val = 0x5C;
else if(car == '/') val = 0x2F;

else if(car == '1') val = 0x31;
else if(car == '2') val = 0x32;
else if(car == '3') val = 0x33;
else if(car == '4') val = 0x34;
else if(car == '5') val = 0x35;
else if(car == '6') val = 0x36;
else if(car == '7') val = 0x37;
else if(car == '8') val = 0x38;
else if(car == '9') val = 0x39;

else if(car == 1) val = 0x31;
else if(car == 2) val = 0x32;
else if(car == 3) val = 0x33;
else if(car == 4) val = 0x34;
else if(car == 5) val = 0x35;
else if(car == 6) val = 0x36;
else if(car == 7) val = 0x37;
else if(car == 8) val = 0x38;
else if(car == 9) val = 0x39;

else if(car == 'a') val = 0x61;
else if(car == 'b') val = 0x62;
else if(car == 'c') val = 0x63;
else if(car == 'd') val = 0x64;
else if(car == 'e') val = 0x65;
else if(car == 'f') val = 0x66;
else if(car == 'g') val = 0x67;
else if(car == 'h') val = 0x68;
else if(car == 'i') val = 0x69;
else if(car == 'j') val = 0x6A;
else if(car == 'k') val = 0x6B;
else if(car == 'l') val = 0x6C;
else if(car == 'm') val = 0x6D;
else if(car == 'n') val = 0x6E;
else if(car == 'o') val = 0x6F;
else if(car == 'p') val = 0x70;
else if(car == 'q') val = 0x71;
else if(car == 'r') val = 0x72;
else if(car == 's') val = 0x73;
else if(car == 't') val = 0x74;
else if(car == 'u') val = 0x75;
else if(car == 'v') val = 0x76;
else if(car == 'w') val = 0x77;
else if(car == 'x') val = 0x78;
else if(car == 'y') val = 0x79;
else if(car == 'z') val = 0x7A;

else if(car == 'A') val = 0x41;
else if(car == 'B') val = 0x42;
else if(car == 'C') val = 0x43;
else if(car == 'D') val = 0x44;
else if(car == 'E') val = 0x45;
else if(car == 'F') val = 0x46;
else if(car == 'G') val = 0x47;
else if(car == 'H') val = 0x48;
else if(car == 'I') val = 0x49;
else if(car == 'J') val = 0x4A;

else if(car == 'K') val = 0x4B;
else if(car == 'L') val = 0x4C;
else if(car == 'M') val = 0x4D;
else if(car == 'N') val = 0x4E;
else if(car == 'O') val = 0x4F;
else if(car == 'P') val = 0x50;
else if(car == 'Q') val = 0x51;
else if(car == 'R') val = 0x52;
else if(car == 'S') val = 0x53;
else if(car == 'T') val = 0x54;
else if(car == 'U') val = 0x55;
else if(car == 'V') val = 0x56;
else if(car == 'W') val = 0x57;
else if(car == 'X') val = 0x58;
else if(car == 'Y') val = 0x59;
else if(car == 'Z') val = 0x5A;

return val;
and this is how is to be used:
name: joinChars
parameters: array

// array is come vector like {'/','l','a','y','e','r',1,'/','c','l','i','p',1,'/','c','o','n','n','e','c','t'};

decl saida,i,size,arraySaida;
size = sizeof(array);
arraySaida=stretch(0,size);

for (i=0;i<size;i++)
{
 arraySaida[i] = converteHex(array[i]);
}

saida = arraytostring(arraySaida);

return saida;
this allow us to make something like this in a button:

decl clicado = firstof(x)+1;

decl endOSC = {'/','l','a','y','e','r',1,'/','c','l','i','p',1,'/','c','o','n','n','e','c','t'};
decl layer = 1;

decl definicaoDeClip = 12;
decl definicaoDeLayer = 6;

endOSC[definicaoDeClip] = clicado;
endOSC[definicaoDeLayer] = layer;

endereco = joinChars(endOSC);

oscout(0,endereco,1);
Is the 2nd block of code supposed to be named "joinChars"?
Do these functions help with concatenating strings?
I'm not at home to test at the moment, but would I be able to monitor/trace additional hex codes to add to the first function (such as a colon:) or is there a limit to characters that are available to the Lemur?

If this works as I think it's intending, then this is something I have wanted for a few weeks, so thank you!
joebataz wrote:once again, newbie question.
how do I define a function with parameters?

TIA,

Joe B
You need to select the folder, on the right, where you want the function to reside. Global functions will be top most, so that it's available to every folder beneath it. After selecting the folder, press the "SCRIPT" button below that window. It will ask you to name the script/function. In the example Leo created for us above, you would name the function convertHex(car). This creates the function "convertHex" with the parameter "car" in parenthesis. Then you can code the function in the multi-line box that appears. The variable "car" will be available immediately as it's "declared" in the function creation. Additional variables will need to be defined with "decl".
Just a little addition. It is possible to define multiple parameters to a script:

test_script(par1, par2, par3)

B.