PDA

View Full Version : Dynamics


fowlplay4
12-01-2006, 12:59 AM
A small concern..

function onCreated() {
temp.func = "onTest";
temp.paramz = {1,2,3};
(@temp.func)(@temp.paramz);
}
function onTest(j,e,r) {
echo("Test:" SPC j SPC e SPC r);
}
/*
RC Output:
Test: 1,2,3 0 0

Result:
j=1,2,3
e=0
r=0

Desired Result:
j=1
e=2
r=3
*/


Is there another way I can workaround this without using else if statements, like in my below example?


function onCreated() {
temp.func = "onTest";
temp.paramz = {1,2,3};
if (temp.paramz.size() == 3) (@temp.func)(temp.paramz[0],temp.paramz[1],temp.paramz[2]);
else if (temp.paramz.size() == 2) (@temp.func)(temp.paramz[0],temp.paramz[1]);
else if (temp.paramz.size() == 1) (@temp.func)(temp.paramz[0]);
}
function onTest(j,e,r) {
echo("Test:" SPC j SPC e SPC r);
}

Skyld
12-01-2006, 01:18 AM
Um, foo({1, 2, 3}); is not the same as foo(1, 2, 3);.

You're giving it an array as the only parameter, therefore you will only get an array.

Chompy
12-01-2006, 01:30 AM
function onCreated() {
temp.func = "onTest";
temp.paramz = {1, 2, 3};
(@temp.func)(@temp.paramz);
}
function onTest(p) {
temp.letters = {NULL, "j", "e", "r"};
this.count = 0;
for(temp.param: temp.p)
{
this.count++;
(@ temp.letters[this.count]) = temp.param;
}
echo("Test:" SPC j SPC e SPC r);
}
Made this fast, dunno if it was something like this

fowlplay4
12-01-2006, 02:49 AM
Hmm..

function onCreated() {
temp.func = "onTest";
temp.paramz = {1,2,3};
(@temp.func)(@temp.paramz);
/*
(@temp.paramz) - returns "1,2,3" not {1,2,3}
I see that "1,2,3" would be a string right?
Would there be a way I could get it recognized as, without using that method Im currently using?
onText(1,2,3); Is what I would like to acheive.
If no one gets what Im saying, thanks anyway.
*/
}

Tolnaftate2004
12-01-2006, 03:25 AM
Hmm..

function onCreated() {
temp.func = "onTest";
temp.paramz = {1,2,3};
(@temp.func)(@temp.paramz);
/*
(@temp.paramz) - returns "1,2,3" not {1,2,3}
I see that "1,2,3" would be a string right?
Would there be a way I could get it recognized as, without using that method Im currently using?
onText(1,2,3); Is what I would like to acheive.
If no one gets what Im saying, thanks anyway.
*/
}

You're only passing one argument...
(@temp.func)(1,2,3);
It's a variable function name, and as such the parameters are sent just like they would in any other function.