Could I get an example of how ScheduledEventArguments works?
by Dave Calabrese · in Torque X 2D · 06/19/2009 (12:50 pm) · 7 replies
Hey all,
I'm diving into XNA with TX2D pretty heavy right now, and also brushing up on my C# at the same time. Making pretty good progress, however when I got to event scheduling, the passing of arguments threw me for a quick loop. I see that the argument type of ScheduledEventArguments gets passed into the scheduled function, however I'm not specifically sure how to properly extrapolate the data from that.
Here's my example on what I'm doing:
Any examples or hints would be greatly appreciated.
Thanks!
I'm diving into XNA with TX2D pretty heavy right now, and also brushing up on my C# at the same time. Making pretty good progress, however when I got to event scheduling, the passing of arguments threw me for a quick loop. I see that the argument type of ScheduledEventArguments gets passed into the scheduled function, however I'm not specifically sure how to properly extrapolate the data from that.
Here's my example on what I'm doing:
//In previous function....
Game.Instance.Engine.GameTimeSchedule.Schedule(3000, animateCrushSequenceForPlayer, 1);
//And then the called function...
void animateCrushSequenceForPlayer(object sender, ScheduledEventArguments scheduleEventArguments)
{
//Stuff happens here. It will be awesome.
}Any examples or hints would be greatly appreciated.
Thanks!
About the author
Recent Threads
#2
Thanks, Gavin!
06/19/2009 (3:40 pm)
Oh!! It passes it over as a string! Clearly I missed that part when reading the source code. No wonder I was confused, lol. I'm here trying to figure out data types and how it sends different kinds over... okay. With strings I can pass anything over I want - awesome.Thanks, Gavin!
#3
06/19/2009 (4:11 pm)
No....you dont have to pass a string, you could do an IntGame.Instance.Engine.RealTimeSchedule.Schedule(1000, dostuff,256);
void dostuff(object sender, ScheduledEventArguments scheduleEventArguments)
{
int x = scheduleEventArguments.DataToSend as int;
}all you have to do is tell it what type of data it is at the other end, so if you want multiple things you wanted to pass in you could wrap them in a class and pass the class over :-)
#4
The error reads:
"The as operator must be used with a reference type or nullable type ('int' is a non-nullable value type)"
06/19/2009 (4:45 pm)
Hrm... actually, I receive an error when doing this to acquire the data:int x = scheduleEventArguments.DataToSend as int;
The error reads:
"The as operator must be used with a reference type or nullable type ('int' is a non-nullable value type)"
#6
06/19/2009 (4:58 pm)
That did it! Thanks, Gavin.
#7
06/19/2009 (5:00 pm)
No worries matey, anytime.
Torque 3D Owner Gavin Beard
Byte Logic
check this post:
http://www.garagegames.com/community/forums/viewthread/94127
I posted a short piece of schedule code in there, with / without argument. hope it helps