Unschedule events?
by Jeremy Tilton · in Torque Game Builder · 03/15/2005 (7:40 pm) · 12 replies
Is there a way to clear the queue of scheduled events? Going back to my tetris thing, I can't use gravity or physics to drop a shape, so I schedule every X milliseconds (based on gamespeed). But what is happening is when i create a new piece, each time the pieces move faster and faster (i'm guessing because old scheduled drops of the piece are still taking place.
About the author
#2
Any reason you can't move them the same way the ship moves in the basic tutorial? Use "$block.setLinearVelocityY( 10 ) "? Seems it would be easier than keeping track of scheduled events.
Robert V Frazier
03/16/2005 (1:50 pm)
@JeremyAny reason you can't move them the same way the ship moves in the basic tutorial? Use "$block.setLinearVelocityY( 10 ) "? Seems it would be easier than keeping track of scheduled events.
Robert V Frazier
#3
03/16/2005 (3:12 pm)
I think i decided against velocity because tetris movement is very chunky. You don't want a smooth transition between spaces, because it makes for a much more complex set of tests for if they created a line. Might make for an interesting game, I'm not sure, but I was aiming for the classic blocky movement of tetris.
#4
I get the following error:
T2D/client/client.cs (230): Unknown command cancel.
Object tileEditorCursorImageMap(34) fxImageMapDatablock2D -> fxBaseDatablock2D -> SimDataBlock -> SimObject
when I used the following code:
$schedule=this.schedule($gamespeed, 0, "dropPiece");
.
.
.
.
$schedule.cancel();
if I use "%this" the object isn't recognized, and the schedule doesn't take place.
03/16/2005 (3:20 pm)
@ Lab:I get the following error:
T2D/client/client.cs (230): Unknown command cancel.
Object tileEditorCursorImageMap(34) fxImageMapDatablock2D -> fxBaseDatablock2D -> SimDataBlock -> SimObject
when I used the following code:
$schedule=this.schedule($gamespeed, 0, "dropPiece");
.
.
.
.
$schedule.cancel();
if I use "%this" the object isn't recognized, and the schedule doesn't take place.
#5
Anyways, I didnt really search much on the forums to see if anyone else did this yet, or had the same problem as i did, though im sure somebody must have wanted to know if one object was above/below/left/right of another object. Melv, any reason you guys put a get/set velocity X/Y but no analog for positions?
Sorry to rant and get offtopic and hijack your thread Jeremy. If you make a tetris style game, im sure ill be one of the first to get addicted (i still play tetris worlds constantly on my xbox. Ive played basically every version since the original gb version). Good luck to you.
Ryan Ackley
Ps. Melv, if you tell me there is a getpositionx or Y function, that I over looked somehow or wasnt in the docs, im gonna go super saijin (ugh, I cant believe i just made a reference to dbz, sick) in 0.4 seconds.
03/16/2005 (3:36 pm)
Hey jeremy, if you are going for a tetris type movement, couldnt you just decide how wide each 'column' is, and then when a player presses left or right (or its time for the block to drop a row) you just use setposition() to move it 10 to the left, right, or down (or however many it would be). The only issue is that getposition() and setposition take a space seperated string instead of an x,y pair. Its STUPID frustrating till you write a few functions to tease them out of there, heres my getpositionY function (i used it to compare the Y values between the ball and the AI paddle in a version of pong i made in about 3 hours last weekend, minus the like 4 i spent digging through the documentation, and finally the engine code, because i didnt have net access)://This is kinda messy, and the +30 isnt the best way to do it
//but it worked. Some tweaking might be needed (i paraphrased this from
//my code, which uses globals, because im lazy)
function getPositionY(%this)
{
%str=%this.getPosition();
%start=strstr(%str," ")+1;
%y=getSubStr(%str. %start, %start+30);
return %y;
}Anyways, I didnt really search much on the forums to see if anyone else did this yet, or had the same problem as i did, though im sure somebody must have wanted to know if one object was above/below/left/right of another object. Melv, any reason you guys put a get/set velocity X/Y but no analog for positions?
Sorry to rant and get offtopic and hijack your thread Jeremy. If you make a tetris style game, im sure ill be one of the first to get addicted (i still play tetris worlds constantly on my xbox. Ive played basically every version since the original gb version). Good luck to you.
Ryan Ackley
Ps. Melv, if you tell me there is a getpositionx or Y function, that I over looked somehow or wasnt in the docs, im gonna go super saijin (ugh, I cant believe i just made a reference to dbz, sick) in 0.4 seconds.
#6
%position = %this.getPosition();
%position.x = getWord(%position, 0);
%position.y = getWord(%position, 1);
03/16/2005 (3:38 pm)
Heh..third time in 2 days, but:%position = %this.getPosition();
%position.x = getWord(%position, 0);
%position.y = getWord(%position, 1);
#7
Thanks stephen, thats more elegent than my code. I still contest there should be a console function to get x/y coords then dealing with space seperated strings. Whats the deal with those anyway?
dangit, im hijacking this thread again. Ugh, I suck.
anyways, thanks stephen
03/16/2005 (3:41 pm)
HA, thats a bit easier than my method, however, on saturday i was at my girlfriends apartment, and she doesnt have any net access, and i was going crazy because i KNOW someone on this board would have saved me 4 hours of punching my laptop (not really) digging through docs and engine code.Thanks stephen, thats more elegent than my code. I still contest there should be a console function to get x/y coords then dealing with space seperated strings. Whats the deal with those anyway?
dangit, im hijacking this thread again. Ugh, I suck.
anyways, thanks stephen
#8
Only difference is which coordinate you alter. The problem isn't moving in chunks, I got that figured out, the problem is that i have a drop scheduled every 500 milliseconds, and when a piece is supposed to stop, I create a new piece. In the create function is a schedule to drop the piece, but if I do not cancel the schedule of the old piece, the new one drops twice as fast because I call them by the same reference.
03/16/2005 (3:44 pm)
Well, moving left/right as well as down is done like you mention. Here is my code for that: which I believe I got from Stephen a couple days ago (C: function pieceLeft()
{
if($canMoveLeft)
{
%currentPosition = $piece.getPosition();
%currentPositionX = getWord(%currentPosition, 0);
%currentPositionY = getWord(%currentPosition, 1);
$piece.setPosition((%currentPositionX - $controlSpeed) SPC %currentPositionY);
$canMoveRight=true;
}
}Only difference is which coordinate you alter. The problem isn't moving in chunks, I got that figured out, the problem is that i have a drop scheduled every 500 milliseconds, and when a piece is supposed to stop, I create a new piece. In the create function is a schedule to drop the piece, but if I do not cancel the schedule of the old piece, the new one drops twice as fast because I call them by the same reference.
#9
$dropschedule=schedule(...);
using %this.schedule SHOULD work, depending if %this is defined.
Im not disagreeing with harold above, ive been out of the torquescript coding for a while, but thats how i recall doing it. Again, it seems like a hack, using global, etc. But if you are only doing a single player oneblockatatime tetris style game, it could work.
03/16/2005 (3:50 pm)
If i recall correctly from tge:$dropschedule=schedule(...);
using %this.schedule SHOULD work, depending if %this is defined.
Im not disagreeing with harold above, ive been out of the torquescript coding for a while, but thats how i recall doing it. Again, it seems like a hack, using global, etc. But if you are only doing a single player oneblockatatime tetris style game, it could work.
#10
03/16/2005 (4:04 pm)
Tried it several ways, cancel isn't working.
#11
the command is:
If you're tying the scedule to an object do:
And to cancel
03/16/2005 (4:21 pm)
Sorry.. my fault, I didn't go back to double check any of my notes.the command is:
cancel($scheduleID);
If you're tying the scedule to an object do:
%obj.scheduleID = %obj.schedule(<schedule stuff here>);
And to cancel
cancel(%obj.scheduleID);
#12
Forgot to say thanks. Thanks Harold!
03/16/2005 (4:35 pm)
It worked! I couldn't do the part about tying the schedule to an object, but the other code worked! It also consequently fixed another weird error I was getting, which I figured was associated to this compacting of schedules. After a few pieces, a bunch of pieces would just start being created at the top and not moving. And they'd keep creating faster and faster until the thing eventually died. I figured this was happening because after a while, the pieces were moving to the bottom so fast, that it was creating exponentially more and more pieces.
Torque Owner Harold "LabRat" Brown
$schedule.cancel();
If you're using a recursive schedule... you'll need to break the loop using some conditional flag of some kind.