Game Development Community

Revising Schedule

by Alex Huck · in Torque Game Engine · 06/01/2006 (7:35 pm) · 1 replies

Hi, I'm trying to remake schedule, so it will be easier to type, with just 2 arguments. But I'm having difficulty:

function StrBetween(%string, %start, %end) {
%strLen = strLen(%string);
%start = StrStr(%string, %start);
%end = StrStr(%string, %end);
%final = GetSubStr(%string, %start+1, %end-%start-1);
return %final;
}

1function Sched(%string, %time) {
2
3 %refObj = getSubStr(%string, 0, strstr(%string, "."));
4 Echo("ref: "@%refObj);
5
6 %function = StrBetween(%string, ".", "(");
7 Echo("func: "@%function);
8
9 %arguments = StrBetween(%string, "(", ")");
10 Echo("arg: "@%arguments);
11
12 if(%refObj == "") {
13 %refObj = 0;
14 Echo("Ref changed to: "@%refObj);
15 }
16
17 Eval("Schedule(1000*%time, %refObj, \"\"@%function, %arguments);");
18
19 Echo("Schedule("@%time*1000@", "@%refObj@", "@%function@", "@%arguments@");");
20}

No, the numbers arn't really there, I added just for reference here. I have pinpointed the problem, but am not sure how to go about fixing it. It lies in "%arguments" If I did Sched("messageAll(1, Hi);", 2); that has 2 arguments (for the messageAll). And that becomes %arguments. But what happens is when it converts it to Torque-form schedule, it looks like Schedule(2000, 0, "messageAll", "1, Hi"); making it think that because "1, Hi" is in quotes, it's one arguments, making it call "MessageAll("1, Hi"); instead of MessageAll(1, Hi); I hope I made my dilemma easy to understand. Ah, yes and StrBetween works fine, returning the Substr between 2 letters

Another question: Is this a good idea, or will this slow the function down too much, making it a bad idea to use many. Because if I was to use this function, I would use it a lot, a real
lot, and I was wondering if it would bog down performance? (Low end machine)

#1
06/02/2006 (3:08 am)
Eval("Schedule(1000*%time, %refObj, \"\"@%function, %arguments);");
This line looks fishy to me. It should be something like:
Eval("Schedule(" @ 1000 * %time @ "," @ %refObj @ ", \"" @ %function @ "\"," @ %arguments @ ");");
As a debugging aid, it really helps if you echo exactly what you are evaluating:
%command = "Schedule(" @ 1000 * %time @ "," @ %refObj @ ", \"" @ %function @ "\"," @ %arguments @ ");";
eval(%command);
echo(%command);
instead of something different as you did.
Quote:
Another question: Is this a good idea, or will this slow the function down too much, making it a bad idea to use many. Because if I was to use this function, I would use it a lot, a real
lot, and I was wondering if it would bog down performance? (Low end machine)
I would rather use the original function. The little advantage in your approach is IMHO not worth the cost.