 |
Castle Paradox
|
View previous topic :: View next topic |
Author |
Message |
Soule X

Joined: 13 Sep 2004 Posts: 131 Location: Indiana
|
Posted: Sun Jan 13, 2013 12:04 pm Post subject: Moving two slices at once... |
|
|
I'm having an issue where I'm running two loops at once, both moving different slices. My problem is there are Wait commands between each movement in each loop and the wait affects both scripts.
What I want to do is make 'Slice A' wait X amount of ticks while 'Slice B' ingnores the waiting and keeps going. How do I achieve this?
EDIT: Okay, after teaching myself how to use timers I think I have it figured out. Except there's one part that is still bothering me.
Previously I had
Code: |
while (Key is Pressed (Key:Left))
do,begin
wait (1)
end |
to get the player stuck in an endless loop if the key was held down. That way the player could not use an "On Key Press" script by holding down the button. He would have to let go of it and press it again.
But now that I can't use a wait command I can't figure out how to emulate it with timers. |
|
Back to top |
|
 |
Bob the Hamster OHRRPGCE Developer

Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
Posted: Sun Jan 13, 2013 3:39 pm Post subject: |
|
|
Try something like this with global variables:
Code: |
single press left := False
if (Key is Pressed (Key:Left)) then(
if(pressing left == False) then(
single press left = True
)
pressing left := True
)else(
pressing left := False
)
if(single press left) then(
do something that should only happen when the key is first pressed, and not when it is held down
)
|
|
|
Back to top |
|
 |
Soule X

Joined: 13 Sep 2004 Posts: 131 Location: Indiana
|
Posted: Sun Jan 13, 2013 5:05 pm Post subject: |
|
|
That's a really ingenious script.
I'm running it from the "On-Keypress Script" on the map, which means once it runs once the only way to get to the 'else' part to reset it is to press a different key...
So when you press left it works and it doesn't let you hold it. But it also doesn't let you let go and press left again until you hit a different button.
EDIT: Okay, ha ha. Finally found a simple solution. Shouldn't have taken me so long...
First I defined the global 'Hold Left' (Global 9)
Code: | If (Key is Pressed (Key:Left) && Hold Left == NO)
Then,begin
# MY ORIGINAL KEY PRESS CODE
Hold Left := YES
Check Key
end
script, Check Key, begin
Switch (Read Global (9))
do,begin
Case (1)
do,begin
if (key is pressed (Key:Left))
then,begin
Set Timer (2,1,1,@Check Key)
end
else (Write Global (9,NO))
end
end
end
|
I feel really stupid for not getting that earlier.
EDIT 2: I should note I defined 'Yes' and 'No' as a constant in case someone else would want to use this script. If so you could just change those to 'On' and 'Off' or whatever. |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Mon Jan 14, 2013 4:37 am Post subject: |
|
|
Is there any reason that you're using writeglobal and readglobal instead of defining a global variable (and using switch instead of if, for that matter)?
We really need a script command for reading only new keypresses.
(If you're OK with getting key-repeat events after a short delay, you can already use the 'keyval' command instead of key is pressed, but that needs a better name too.) _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
Soule X

Joined: 13 Sep 2004 Posts: 131 Location: Indiana
|
Posted: Mon Jan 14, 2013 7:34 am Post subject: |
|
|
Ha ha. I noticed both those things a little bit later. I have no idea why I did it that way. I'm pretty sure I used the 'switch' command because I had just got done working with the timers and switches. Usually when I'm scripting I just sort of go on autopilot for a while. I don't really think about what I'm typing if my brain knows it will work.
Funny you should mention that though, because about ten minutes after that post I spotted it and was like wtf and changed it. lol
Have we always been able to use fractions of a tick? I don't remember being able to do that. But I haven't used OHR in a while. And here I've been using only whole numbers like a chump. |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Wed Jan 16, 2013 4:30 pm Post subject: |
|
|
I don't know what you mean. You can't use fractions of a tick, you can't yet change the frame/tick rate (which are both 18.2 fps), and you can't use floating point numbers in HamsterSpeak.
Note that if you wrote something like "wait(1/4)" that 1/4 rounds down to 0. (Also, wait(0) is actually equivalent to wait(1)) _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
Soule X

Joined: 13 Sep 2004 Posts: 131 Location: Indiana
|
Posted: Wed Jan 16, 2013 11:56 pm Post subject: |
|
|
Yeah, after messing around with it more I'm not really sure what happened. I have two animations that are virtually identical except one goes left and one right. When I set one for 7/10 ticks (with a timer) it goes significantly faster than the one with frames set at 1 tick. If I reverse all the numbers then the other animation goes faster. So 7/10 ticks goes faster than 1 tick...
But then I tried going lower (2/10, 1/100, etc) and nothing seemed to happen... weird.
So I just made a quick little test game to see if I was crazy or not. I made five rats each set to a separate timer. They were set at 1 tick increments, but to count down at 1, 8/10, 6/10, 4/10, and 2/10 respectively. Each increment they would move one pixel right. Here's what happened:
As you can see the one set to move every 1 tick was way slower than the others. On the other hand, as long as it was set below 1 it did not matter what the number was. It did not affect the speed after that.
I don't know what this means. Maybe it's some sort of bug or something. Not really sure. But this is what made me start using fractional numbers.
Here's the code:
Code: | include, plotscr.hsd
global variable (0,Rat01)
global variable (1,Rat01x)
global variable (2,Rat02)
global variable (3,Rat02x)
global variable (4,Rat03)
global variable (5,Rat03x)
global variable (6,Rat04)
global variable (7,Rat04x)
global variable (8,Rat05)
global variable (9,Rat05x)
script, Race,sprite,y, begin
if (Read Global (sprite))
then,begin
free slice (Read Global (sprite))
end
variable(sl)
sl := load small enemy sprite (sprite)
slice to front (sl)
Write Global (sprite,sl)
set slice x (Read Global (sprite), Read Global (sprite + 1))
set slice y (Read Global (sprite), y)
end
plotscript, Start, begin
Put Camera (0,0)
Set Timer (0,1,1,@Rat One)
Set Timer (1,8/10,1,@Rat Two)
Set Timer (2,6/10,1,@Rat Three)
Set Timer (3,4/10,1,@Rat Four)
Set Timer (4,2/10,1,@Rat Five)
end
script, Rat One, begin
Set Timer (0,1)
Race (0,0)
Rat01x += 1
end
script, Rat Two, begin
Set Timer (1,8/10)
Race (2,40)
Rat02x += 1
end
script, Rat Three, begin
Set Timer (2,6/10)
Race (4,80)
Rat03x += 1
end
script, Rat Four, begin
Set Timer (3,4/10)
Race (6,120)
Rat04x += 1
end
script, Rat Five, begin
Set Timer (4,2/10)
Race (8,160)
Rat05x += 1
end |
EDIT: I should clarify I'm using the latest stable release version alectormancy+2 |
|
Back to top |
|
 |
Bob the Hamster OHRRPGCE Developer

Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
Posted: Thu Jan 17, 2013 7:17 am Post subject: |
|
|
Code: |
Set Timer (0,1,1,@Rat One)
Set Timer (1,8/10,1,@Rat Two)
Set Timer (2,6/10,1,@Rat Three)
Set Timer (3,4/10,1,@Rat Four)
Set Timer (4,2/10,1,@Rat Five)
|
This is the same as:
Code: |
Set Timer (0,1,1,@Rat One)
Set Timer (1,0,1,@Rat Two)
Set Timer (2,0,1,@Rat Three)
Set Timer (3,0,1,@Rat Four)
Set Timer (4,0,1,@Rat Five)
|
Rats Two, Three, Four and Five move once per tick. Rat One moves every other tick.
Neither "wait" nor timers can divide a tick.
There is however, a trick for movement that you might find useful. The "move slice by" and "move slice to" commands allow you to move a slice more precisely than you can do with timer or wait steps. This is not because "move slice to" and "move slice by" support smaller slices of a tick, but because they support smaller slices of a pixel, (if that makes any sense) |
|
Back to top |
|
 |
Soule X

Joined: 13 Sep 2004 Posts: 131 Location: Indiana
|
Posted: Thu Jan 17, 2013 8:52 am Post subject: |
|
|
Oh, okay I see what you're saying. So setting a timer for (1,0,1,@Something) makes it wait one tick? That is where I got confused.
As far as the commands you mentioned, what I'm doing is moving sprites around in very precise animation patterns. They aren't moving across the screen (most of the time). They are moving, say, up 2 pixels, down 2 left 2, up 3 right 7, etc. The problem is the movements have to be those exact pixel locations. The speed at which they arrive there is the only problem. I've had to cut frames to speed it up, which I don't like.
I'm not sure if those commands could help me.
EDIT: After playing around with it some I think it could help on certain sections of the animation. Specifically when the sprite 'slides' in a straight line. It would be nice if you could set several points for one 'Move Slice by' command somehow.
Like: Move 2,7 -3,6 4,-6 all in one tick. That would solve all my problems. |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Fri Jan 25, 2013 5:32 am Post subject: |
|
|
Opps, I never read the end of this thread.
Regarding multiple points for "move slice by": I'd like to see a version for moving slices along Bezier (or other parametric) curves.
But what you really want is a higher framerate. And you might be in luck there relatively soon. But do you really want to make 3 steps of that size per 'tick' (ie roughly 60 steps a second)? _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
Soule X

Joined: 13 Sep 2004 Posts: 131 Location: Indiana
|
Posted: Fri Jan 25, 2013 8:13 am Post subject: |
|
|
No, probably not. That was just an example I threw random numbers into.
But say you want like a jumping animation that's really fast. Right now you would have to set each point so that the character doesn't jump diagonally in a straight line. Then you have to adjust the timing of each part so that it animates at roughly the same speed. And if any part of the animation is less than 1 tick long you would have to cut frames or make the animation slower.
But yeah, the frame rate would solve that to an extent. |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Sun Jan 27, 2013 6:03 am Post subject: |
|
|
This only answers part of what you talked about, but for jumping movements I always use a for loop that moves the character in an arc. Something like (jumping straight up)
Code: |
variable (vz)
for (vz, 5, -5, -1) do (
set hero z (me, hero z (me) + vz)
wait
)
|
Edit: just added the 'hero z' command which was missing. Obviously you can use hero y instead. _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|