Game Development Community

a huge behavior relying on schedule currently unreliable.

by rennie moffat · in iTorque 2D · 07/14/2010 (7:58 pm) · 6 replies

Hi,
I am having some trouble, perhaps I should have posted in TGB but iTGB seems more helpful, however this is just a plain coding behavior issue. The premise of the behavior is an instructions page. I have about a dozen images (which are sentences, each describing an aspect of the game. The screen stays at "0 0" and on schedule sentence 1 comes up, then on schedule goes away, sentence 2 then comes up and so on, however I have noticed two things.


1. I originally did the behavior with layers, setting the sentence object above and below the background. I did get this to work sometime ago but now, it sometimes places an object out way ahead of schedule on level loaded and it remains there, despite the fact onBehaviorAdd I set each to be behind the background layer.


2. Well after getting annoyed enough I set it so that they (sentences) would simply move positions, instead of layers. but same issues. It basically is not accurate enough.


I am posting some of the behavior here, any help, ideas, thoughts would be helpful.


Cheers
Rennie


ps. I have actually just posted the whole thing. It is quite huge so please excuse, but each note/notice is an object that gets pulled out and in. The "scheds" are the time they get pulled in an out at relative to the last function.

Basically what I am wondering is, A. does anyone have any better suggestions for what I am trying to do and B, my doubhts tell me that maybe the behavior is too big and complex.




Cheers Again.

if(!isObject(instructLyBehavior)){
	%template = new behaviorTemplate(instructLyBehavior);
	
	%template.friendlyName = "instructLyBehavior";
	%template.description = "instructLyBehavior";
	%template.behaviorType = "instructions";
//temple intro
	%template.addBehaviorField(thisGuyASched, "", float, "2000");
	%template.addBehaviorField(thisGuy, "", object, "thisGuy", t2dSceneObject);
	%template.addBehaviorField(thisGuyPt, "", Point2F, "5.070 -24.274");
	%template.addBehaviorField(thisGuy2Sched, "", float, "1700");
	%template.addBehaviorField(templeRacer, "", object, "templeRacer", t2dSceneObject);
	%template.addBehaviorField(templeRacerPt, "", Point2F, "22.463 -17.239");
	%template.addBehaviorField(thisGuyBSched, "", float, "5000");
	///tap notice
	%template.addBehaviorField(tapASched, "", float, "500");
	%template.addBehaviorField(tapNotice, "", object, "tap", t2dSceneObject);
	%template.addBehaviorField(tapPt, "", Point2F, "39.530 -2.959");
	%template.addBehaviorField(tapBSched, "", float, "9000");
	
//timer notes/objetcs	
	%template.addBehaviorField(timerASched, "", float, "1500");
	%template.addBehaviorField(timerNotice, "timerDesc1", object, "", t2dSceneObject);
	%template.addBehaviorField(timerNoticePt, "", Point2F, "14.853 30.455");
	%template.addBehaviorField(timerNotice2Sched, "", float, "4000");
	%template.addBehaviorField(timerNotice2, "timerDesc2", object, "", t2dSceneObject);
	%template.addBehaviorField(timerNotice2Pt, "", Point2F, "18.185 19.288");
	%template.addBehaviorField(timerNotice3Sched, "", float, "4000");
	%template.addBehaviorField(timerNotice3, "timerDesc3", object, "", t2dSceneObject);
	%template.addBehaviorField(timerNotice3Pt, "", Point2F, "39.485 8.407");
	%template.addBehaviorField(timerBSched, "", float, "7000");
	
///enemyreward notes objects
	%template.addBehaviorField(enemyASched, "", float, "500");
	%template.addBehaviorField(enemyNote1, "", object, "enemyDesc1", t2dSceneObject);
	%template.addBehaviorField(enemyNote1Pt, "", Point2F, "6.664 -23.051");
	%template.addBehaviorField(enemyNote2Sched, "", float, "3000");
	%template.addBehaviorField(enemyNote2, "", object, "enemyDesc2", t2dSceneObject);
	%template.addBehaviorField(enemyNote2Pt, "", Point2F, "25.381 10.402");
	%template.addBehaviorField(enemyNote3Sched, "", float, "3000");
	%template.addBehaviorField(enemyNote3, "", object, "enemyDesc3", t2dSceneObject);
	%template.addBehaviorField(enemyNote3Pt, "", Point2F, "24.994 -8.532");
	%template.addBehaviorField(enemy1, "", object, "enemyObject", t2dSceneObject);
	%template.addBehaviorField(enemy2, "", object, "enemyObject", t2dSceneObject);
	%template.addBehaviorField(enemy3, "", object, "enemyObject", t2dSceneObject);
	%template.addBehaviorField(enemy4, "", object, "enemyObject", t2dSceneObject);
	%template.addBehaviorField(enemy5, "", object, "enemyObject", t2dSceneObject);
	%template.addBehaviorField(enemyPt, "", Point2F, "-39.206 -8.345");
	%template.addBehaviorField(enemyBSched, "", float, "15000");
////reward notes/objects
	%template.addBehaviorField(rewardASched, "", float, "3000");
	%template.addBehaviorField(reward1, "", object, "reward1", t2dSceneObject);
	%template.addBehaviorField(reward1Pt, "", Point2F, "-27.173 -16.218");
	%template.addBehaviorField(reward2, "", object, "reward2", t2dSceneObject);
	%template.addBehaviorField(reward2Pt, "", Point2F, "-12.891 -8.103");
	%template.addBehaviorField(reward3, "", object, "reward3", t2dSceneObject);
	%template.addBehaviorField(reward3Pt, "", Point2F, "1.553 -0.151");
	%template.addBehaviorField(reward4, "", object, "reward3", t2dSceneObject);
	%template.addBehaviorField(reward4Pt, "", Point2F, "-43.240 -9.077");
	%template.addBehaviorField(reward5, "", object, "reward3", t2dSceneObject);
	%template.addBehaviorField(reward5Pt, "", Point2F, "-29.445 -0.475");
	%template.addBehaviorField(reward6, "", object, "reward3", t2dSceneObject);
	%template.addBehaviorField(reward6Pt, "", Point2F, "-15.975 7.802");
	%template.addBehaviorField(reward7, "", object, "reward3", t2dSceneObject);
	%template.addBehaviorField(reward7Pt, "", Point2F, "-45.674 6.990");
	%template.addBehaviorField(reward8, "", object, "reward3", t2dSceneObject);
	%template.addBehaviorField(reward8Pt, "", Point2F, "-31.392 15.429");
	%template.addBehaviorField(rewardNotice1, "", object, "timerRewardDesc1", t2dSceneObject);
	%template.addBehaviorField(rewardNotice1Pt, "", Point2F, "8.887 -23.682");
	%template.addBehaviorField(rewardNotice2, "", object, "timerRewardDesc2", t2dSceneObject);
	%template.addBehaviorField(rewardNotice2Pt, "", Point2F, "18.185 19.288");
	%template.addBehaviorField(rewardNotice2Sched, "", float, "3000");
	%template.addBehaviorField(rewardNotice3, "", object, "timerRewardDesc3", t2dSceneObject);
	%template.addBehaviorField(rewardNotice3Pt, "", Point2F, "42.436 3.425");
	%template.addBehaviorField(rewardNotice3Sched, "", float, "3000");
	%template.addBehaviorField(rewardBSched, "", float, "10000");
	
	/////
	%template.addBehaviorField(concludeSched, "", float, "2000");
	%template.addBehaviorField(concludePt, "", Point2F, "28.913 -11.341");
	%template.addBehaviorField(conclude, "", object, "conclusion", t2dSceneObject);
	%template.addBehaviorField(greenGod, "", object, "greenGod", t2dSceneObject);
	%template.addBehaviorField(greenGodPt, "", Point2F, "38.243 -24.091"); 
	%template.addBehaviorField(instructsReplayBtn, "", object, "instructBtn", t2dSceneObject);
	%template.addBehaviorField(instructsReplayBtnPt, "", Point2F, "30.280 32.105");
	%template.addBehaviorField(mainMenuBtn, "", object, "mainMenuBtn", t2dSceneObject);
	%template.addBehaviorField(mainMenuBtnPt, "", Point2F, "35.971 26.066");
	%template.addBehaviorField(playBtn, "", object, "playBtn", t2dSceneObject);
	%template.addBehaviorField(playBtnPt, "", Point2F, "39.207 20.265");
	/////
	%template.addBehaviorField(layer0, "", int, "0");
	%template.addBehaviorField(layer31, "", int, "31");
	%template.addBehaviorField(layerMouser, "", int, "5");
	
	////
	%template.addBehaviorField(waitPos, "", Point2F, "-200 -200");
	
}

function instructLyBehavior::onBehaviorAdd(%this){
	%this.schedule(%this.thisGuyASchedule, thisGuyA);
	%this.owner.enableUpdateCallback();
	%this.thisGuy.setPosition(%this.waitPos);
	%this.templeRacer.setPosition(%this.waitPos);
	%this.tapNotice.setPosition(%this.waitPos);
	%this.timerNotice.setPosition(%this.waitPos);
	%this.timerNotice2.setPosition(%this.waitPos);
	%this.timerNotice3.setPosition(%this.waitPos);
	%this.reward1.setPosition(%this.waitPos);
	%this.reward2.setPosition(%this.waitPos);
	%this.reward3.setPosition(%this.waitPos);
	%this.reward4.setPosition(%this.waitPos);
	%this.reward5.setPosition(%this.waitPos);
	%this.reward6.setPosition(%this.waitPos);
	%this.reward7.setPosition(%this.waitPos);
	%this.reward8.setPosition(%this.waitPos);		
	%this.rewardNotice1.setPosition(%this.waitPos);
	%this.rewardNotice2.setPosition(%this.waitPos);
	%this.rewardNotice3.setPosition(%this.waitPos);
	%this.enemy1.setLayer(%this.layer31);
	%this.enemy2.setLayer(%this.layer31);
	%this.enemy3.setLayer(%this.layer31);
	%this.enemy4.setLayer(%this.layer31);
	%this.enemy5.setLayer(%this.layer31);
	%this.enemyNote1.setPosition(%this.waitPos);	
	%this.enemyNote2.setPosition(%this.waitPos);		
	%this.enemyNote3.setPosition(%this.waitPos);	
	%this.conclude.setPosition(%this.waitPos);	
	%this.greenGod.setPosition(%this.waitPos);	
	%this.playBtn.setPosition(%this.waitPos);
	%this.instructsReplayBtn.setPosition(%this.waitPos);
}
	

////add thisGuy 3 secs wait next....	
function instructLyBehavior::thisGuyA(%this){
	%this.thisGuy.setPosition(%this.thisGuyPt);	
	%this.schedule(%this.thisGuy2Sched, thisGuy2Load);
}
///add thisGuy2
function instructLyBehavior::thisGuy2Load(%this){
	%this.templeRacer.setPosition(%this.templeRacerPt);		
	%this.schedule(%this.thisGuyBSched, thisGuyB);
}

////add nothing secs wait next....
function instructLyBehavior::thisGuyB(%this){
	%this.thisGuy.setPosition(%this.waitPos);			
	%this.templeRacer.setPosition(%this.waitPos);	
	%this.schedule(%this.tapASched, tapA);
}

////add tapNotice 3 secs wait next....
function instructLyBehavior::tapA(%this){
	%this.tapNotice.setPosition(%this.tapPt);	
	%this.schedule(%this.tapBSched, tapB);
}

///put tap and guy away.
function instructLyBehavior::tapB(%this){
	%this.tapNotice.setPosition(%this.waitPos);	
	%this.schedule(%this.timerASched, timerA);
}

///this set this timerNotice 3000
function instructLyBehavior::timerA(%this){
	%this.timerNotice.setPosition(%this.timerNoticePt);	
	%this.schedule(%this.timerNotice2Sched, timerNote2);
}

///set timer 2
function instructLyBehavior::timerNote2(%this){
	%this.timerNotice2.setPosition(%this.timerNotice2Pt);	
	%this.schedule(%this.timerNotice3Sched, timerNote3);
}

///timer note 3 set... 
function instructLyBehavior::timerNote3(%this){
	%this.timerNotice3.setPosition(%this.timerNotice3Pt);	
	%this.schedule(%this.timerBSched, timerB);
}

///remove timers.....
function instructLyBehavior::timerB(%this){
	%this.timerNotice.setPosition(%this.waitPos);	
	%this.timerNotice2.setPosition(%this.waitPos);	
	%this.timerNotice3.setPosition(%this.waitPos);	
	%this.schedule(%this.enemyASched, enemyA);
}

//// set enemy and enemyNote
function instructLyBehavior::enemyA(%this){
	%this.enemy1.setLayer(%this.layerMouser);
	%this.enemy2.setLayer(%this.layerMouser);
	%this.enemy3.setLayer(%this.layerMouser);
	%this.enemy4.setLayer(%this.layerMouser);
	%this.enemy5.setLayer(%this.layerMouser);
	%this.enemyNote1.setPosition(%this.enemyNote1Pt);	
	%this.schedule(%this.enemyNoteSched, enemyNote);
}

/// set enemy note 2
function instructLyBehavior::enemyNote(%this){
	%this.enemyNote2.setLayer(%this.layer0);
	%this.schedule(%this.enemyBSched, enemyB);
}
/// remove
function instructLyBehavior::enemyB(%this){
	%this.enemy1.setLayer(%this.layer31);
	%this.enemy2.setLayer(%this.layer31);
	%this.enemy3.setLayer(%this.layer31);
	%this.enemy4.setLayer(%this.layer31);
	%this.enemy5.setLayer(%this.layer31);
	%this.enemyNote1.setPosition(%this.waitPos);	
	%this.enemyNote2.setPosition(%this.waitPos);	
	%this.schedule(%this.rewardASched, rewardA);
}

////set rewards and note
function instructLyBehavior::rewardA(%this){
	%this.reward1.setPosition(%this.reward1Pt);
	%this.reward2.setPosition(%this.reward2Pt);
	%this.reward3.setPosition(%this.reward3Pt);
	%this.reward4.setPosition(%this.reward4Pt);
	%this.reward5.setPosition(%this.reward5Pt);
	%this.reward6.setPosition(%this.reward6Pt);
	%this.reward7.setPosition(%this.reward7Pt);
	%this.reward8.setPosition(%this.reward8Pt);
	%this.rewardNotice1.setPosition(%this.rewardNotice1Pt);
	%this.schedule(%this.rewardNotice2Sched, rewardNotice2Place);
}

///set rewardNotice2
function instructLyBehavior::rewardNotice2Place(%this){
	%this.rewardNotice2.setPosition(%this.rewardNotice2Pt);
	%this.schedule(%this.rewardBSched, rewardNotice3Place);
}
function instructLyBehavior::rewardNotice3Place(%this){
	%this.rewardNotice3.setPosition(%this.rewardNotice3Pt);
	%this.schedule(%this.rewardBSched, rewardB);
}

///remove rewards
function instructLyBehavior::rewardB(%this){
	%this.reward1.setPosition(%this.waitPos);
	%this.reward2.setPosition(%this.waitPos);
	%this.reward3.setPosition(%this.waitPos);
	%this.reward4.setPosition(%this.waitPos);
	%this.reward5.setPosition(%this.waitPos);
	%this.reward6.setPosition(%this.waitPos);
	%this.reward7.setPosition(%this.waitPos);
	%this.reward8.setPosition(%this.waitPos);
	%this.rewardNotice1.setPosition(%this.waitPos);
	%this.rewardNotice2.setPosition(%this.waitPos);
	%this.rewardNotice3.setPosition(%this.waitPos);
	%this.schedule(%this.concludeSched, conclude);
}

/// set conclusion
function instructLyBehavior::conclude(%this){
	%this.conclude.setPosition(%this.concludePt);	
	%this.owner.setPosition(%this.greenGodPt);
	%this.playBtn.setPosition(%this.playBtnPt);
	%this.instructsReplayBtn.setPosition(%this.instructsReplayBtnPt);
}

About the author

My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.


#1
07/14/2010 (10:34 pm)
Rennie, I have studied your code, for what you are trying to achieve it looks correct, so, when you say it is not accurate, can you be more specific please ?
#2
07/15/2010 (12:36 am)
Well I am experiencing two things.


1. Not all images are being called, as in not all show up tho I am sure my datablocks are good.

2. Sometimes, it does work, however sometimes, an image, say the 3rd one called for example (this can vary) is up on screen at the beginning of the level, when it should not and may stay the duration of all the schedules, which it should not.

It is very frustrating.



::?

My question tho is, when a behavior has a schedule to say call an object up to a visible point, in the editor, we can see this work, live. So, when I run the game say, half way through the schedules (in the editor) so I can see the 8th object is up, I run the game, the level starts with that 8th object up and everything seems to get confused or logged jammed.


I need to insure that objects are only visible when they need to be. Beyond doing that in onBehaviorAdd, initiate location and via schedules, I am not sure what to do.



#3
07/15/2010 (9:27 am)
Rennie, I'm not sure if this would work for you ... rather than using behaviors etc

- Create an array of your objects with an index, 0,1,2,3,4
- Create a looping schedule that is called every 3000 ms e.g. showNextHelp
- In showNextHelp you maintain and track your index and display the appropriate object from the array
- When the index reaches the last object you no longer call the timer and exit the function

This means that all the object displaying code for the help is in a single place.


#4
07/15/2010 (9:47 pm)
Thanks again Scott,
I am currently uncomfortable with arrays. I am going to spend the next year studying them (not full time, but to get a grasp) So Unless you can describe them, so I get a full understanding, or show a quick example... don't worry about it.


I have noticed something tho. In another behavior which was reliant on schedules, it too was acting up (weird tho as I have tons of behaviors which use schedules and most work fine. What I did to correct the problem was simply place a number say "300" in the schedule as opened to %this.shecduleTime and it works as should. I am going to go back and redo the threads behavior with numbers instead of floats as called by %this. This I am very hopeful will works as I had noticed my echo call to the schedule time amount (float) was not being called.
#5
07/16/2010 (12:41 am)
Quick example of arrays and for loops.

If you are concerned that there might be an issue or bug with schedule, you can put those fears aside. Calls to schedule() are the juice that make my game go and they work 100% of the time.

You might check for typos.

Another really great option is to put echo-statements in each of your functions. I'll bet that one of the functions doesn't get called (which would stop the rest from working). Once you find that function, you'll probably see the error immediately.
#6
07/16/2010 (1:12 am)
Thanks William, and I will reference that thread for sure.


Yah for some reason the schedules, for me, work much better when I put in the numbers in the schedule, as opposed to referencing a behaviorField, float. Anyhow, it is weird as I have plenty of behaviors which do reference a behaviorField float to call the schedule time.

Another trick, in my case I just thought of and it works, is using onLevelLoaded to set all layers and positions. OnBehaviorAdd set things where there were in the editor at the time I hit run game, so, as a result they appeared in the screen, inappropriately at load time.