schedule return value question
by Amjad Yahya · in Torque Game Builder · 12/06/2011 (2:41 am) · 3 replies
I have this function that returns a true or false value like this:
%match=%obj.checkmatches();
but if I use a schedule function like this:
%match=%obj.schedule(500,"checkmatches");
the return value -as it says in the documentations- will return an event id value.
How can I solve this? I must use "schedule" and must know the return value.
Any ideas.
Thanks.
%match=%obj.checkmatches();
but if I use a schedule function like this:
%match=%obj.schedule(500,"checkmatches");
the return value -as it says in the documentations- will return an event id value.
How can I solve this? I must use "schedule" and must know the return value.
Any ideas.
Thanks.
About the author
#2
12/06/2011 (7:47 am)
Yes, I agree with Conor. You need to save off the result inside the checkmatches() function. It's probably easiest to use some a global variable, though depending upon exactly what you need to know you may want to stick it in some other structure. Then you can check %match against that global variable/structure instead.
#3
If you "must use schedule," then here is one suggestion. Of course, I don't know exactly what you're wanting to do in your actual code.
In the above, you fire off the scheduled event and let other code take care of what it's supposed to do with the result. In the original function you continue doing your additional work that doesn't involve the result. The "checkMatches" function could be a global function instead of a member function on MyObject, depending on what you're trying to do.
You can keep checkMatches in a super class and override onCheckMatches for more specific subclasses/object.
Did I overly complicate things?
12/09/2011 (2:07 pm)
It depends on what you're trying to accomplish. You might want to consider rethinking things. Maybe scheduling another intermediate method. Then that method will call the actual checking method and handle the %match results. When you use something like schedule, it's usually a fire-and-forget within the scope of the current function.If you "must use schedule," then here is one suggestion. Of course, I don't know exactly what you're wanting to do in your actual code.
function myFunction()
{
%obj.schedule(500,"checkMatches");
// Throw up a gui with text saying "checking for matches"
matchesGui.Visible = true;
matchesGui.status.text = "Checking for matches...";
// .. continue doing other stuff
}
function MyObject::checkMatches(%this)
{
%matches = %this.onCheckMatches();
if (%matches)
{
matchesGui.status.text = "Matches found.";
} else {
matchesGui.status.text = "No matches found.";
doSomethingHere();
}
// ... do other things with %matches here
}
function MyObject::onCheckMatches(%this)
{
// ... do some stuff and get a true/false result
return true;
}In the above, you fire off the scheduled event and let other code take care of what it's supposed to do with the result. In the original function you continue doing your additional work that doesn't involve the result. The "checkMatches" function could be a global function instead of a member function on MyObject, depending on what you're trying to do.
You can keep checkMatches in a super class and override onCheckMatches for more specific subclasses/object.
Did I overly complicate things?
Conor O'Kane
cokane.com