Post new topic    
Page 1, 2  »
Slime
Send private message
More simultaneous actions 
 PostFri Jan 04, 2013 4:15 pm
Send private message Reply with quote
Hey,
another thread of mine being a beginner in the programming game.
I'd like to have a on-key-press script, that only reacts to specific keys and then exits the script, that can be triggered while certain scripts are already running.

Now I tried to figure out certain ways.
A "Key wait"-script would stop the entire script until a key is pressed, which is not what I want, it should continue going on.
I tried to make a "while-loop" with
Code:

while (keyval (key:NUMPAD PLUS) == 0) do
begin
backdrops2 (67,69,20,1)
show text box (69)
(rest of a longer animation script)

but it only checks this at the very beginning of the script, and doesn't do anything until the entire animation script of mine has already ran through.
Basically an if/then statement that just keeps on checking while the script is going further is what I would need!
thanks in advance
score
Liquid Metal King Slime
Send private message
 
 PostFri Jan 04, 2013 5:29 pm
Send private message Reply with quote
Tell us more about what you are trying to do. Is this for a mini-game? If so, how do you want it to work?
Liquid Metal King Slime
Send private message
 
 PostFri Jan 04, 2013 7:00 pm
Send private message Reply with quote
It sounds like what would you need is a while loop with a counter.
The counter would be a variable that would increase in value everytime the loop started over. Then in order to time things you would give them If commands checking the counter. Like...
Code:
If (counter==456) Then ( showtextbox(12) )
If (counter==476) Then ( advancetextbox )

You'd also have to make sure you place a wait(1) command inside the loop somewhere.
The counter value would basically be the number of ticks (1/16th of a second) it's been since the beginning of the script, so you could time things out that way.
Hope this helps.
Slime
Send private message
 
 PostTue Jan 08, 2013 6:46 am
Send private message Reply with quote
Hey thanks spoonweaver, although this isn't really exactly what I was searching for.
I'll try to express myself more clearly:
What I basically want to do is an animation sequence, that uses backdrops and textboxes.
However I want to add in the possibility of interrupting this sequence through the pressing of certain keys, and temporarily stop it while starting up another animation.
Now after this second animaition is finished, it should continue the previous one from where it stopped before. Angel
Liquid Metal King Slime
Send private message
 
 PostTue Jan 08, 2013 8:33 am
Send private message Reply with quote
Well, if this is what you'd like to do, you can instead have the while loop be focused on the value of the counter variable. When the counter variable gets high enough, the loop stops and the cutscene ends. Then you could add in a check every loop to see if the buttons are pressed and if they are you'd run another script. (by simply writing it's name)
Then, the other script would run, stopping the first one. Then when it was done the other script would pick up where it left off.
Make sure to make the counter variable a global though, otherwise you might end up losing your place in the original cutscene.
Slime
Send private message
 
 PostTue Jan 08, 2013 10:53 am
Send private message Reply with quote
Ok, my pre-mature hamsterspeak skills are experiencing some lingual disorientation here.
How do make a working counter? Confused Edit: Ok figured out the math but not more than that...
for the sake of learning I'll add my not working code's here.
Code:

#lets say my global variable would be ctr4
script, startcounter,begin
variable (ctr3)   
for (ctr3,1,1000) do (INCREMENT(ctr4),wait(1),
 if (key is pressed(key:NUMPAD PLUS)) then(animation2))
end
###and now, how do I integrate this??
plotscript,doubleanimation,begin
startcounter
while (ctr4 <<500) do (animation1)
end
Red Slime
Send private message
 
 PostTue Jan 08, 2013 3:49 pm
Send private message Reply with quote
Oh, may I jump in?

You're on the right track, you just need to have both parts in one place. I don't think you'd need a global, though. Here's how I would write it, based on your code sample:

Code:

script, animation 1, begin
   variable(counter)

   for(counter, 1, 1000)do, begin
      if(key is pressed(key:NUMPAD PLUS))then (animation 2)

      #here is where your original animation goes, only each should be prefaced by an
      #"if(counter == n)"
      if(counter == 1) then (show textbox(X))
      if(counter == 2) then (load backdrop(Y))
      if(counter == 3) then (set npc direction(Z, up))
      ...
      if(counter == 244) then (show textbox(whatever))
      ...
      if(counter == 1000) then (we are finally, finally done)

      wait(1)
   end

end


The "(counter == n)" parts would basically replace your "wait(n)" commands in the original animation.

For example, if you had

Code:

show textbox(0)
wait(30)
load backdrop(22)
wait(20)
show textbox(1)
etc...


In your original code, the new code would look like this:

Code:

if(counter == 1) then (show textbox(0))
if(counter == 31) then (load backdrop(22))
if(counter == 51) then (show textbox(1))
etc...


Actually, it might look better if you did it as a series of switch-cases (I love switch-cases in HamsterSpeak). If so, then you could do it like this:

Code:

switch(counter) do
(
   case(1) do (show textbox(0))
   case(31) do (load backdrop(22))
   case(51) do (show textbox(1))
)


And then animation 2 would just be a "normal" animation script with waits and so forth (like how you wrote your original). Once it finished, it would just jump back into the original code and continue.

Some things to note: The way you've described it, and the way I've written it, the user will be able to fire off "animation 2" multiple times. Also, "animation 2" can be fired off at any time in the original animation (so, like 2 ticks into the first one, if NUMPAD PLUS is pressed, animation 2 will go off). I'm not saying these are bad things, just things to keep in mind; each can be prevented with some code-tweaking, too.
Slime
Send private message
 
 PostTue Jan 08, 2013 10:48 pm
Send private message Reply with quote
Hey sotrain, I appreciate your jumping in! So far, you solution seems quite unhandy, as I got some more for()do()-blocks that run several times inside the original animation, so if I had the if-cases inside a new loop,
Code:

for(counter, 1, 1000)do, begin    
   if(key is pressed(any key))then (cityopenup)
suspend player
#wait (100)
variable (z)
if (counter == 101) then (for (z,1,3) do
if (counter == 102) then (textboxflash(61,62,3)) #there's 2x a wait of 3 ticks in here
end
)

the counter would be already off the second time the block runs. Means I'd have to write those down then five times instead of 5 times in a for-loop, putting the correct if(counter == n) before it? That would be quite an enormous code-hassle (as it would be already if there'd be no for-loops). Also, other elements like a "wait for textbox" doesn't seem to work well with anything afterwards. However if it's the only possibility I'd consider it.
p.s.
here is an excerpt from the first half of the original animation/sound sequence
Code:

advance text box
show text box (64)
wait for text box
suspend player
wait (100)
variable (z)
for (z,1,3) do
(textboxflash(61,62,3)
end
wait (35)
advance text box
wait (8)
for (z,1,3) do
(textboxflash(61,62,3)
end
wait (100)
advance text box
wait (20)
#4-zacker
for (z,1,5) do (textboxscript2(62,1,2))
wait (6)
for (z,1,4) do (textboxscript2(62,1,2))
wait (6)
show text box (61)
wait (9)
show text box (62)
wait (35)
advance text box
wait (35)
Metal Slime
Send private message
 
 PostTue Jan 08, 2013 11:23 pm
Send private message Reply with quote
If we simply want a keypress to INTERRUPT the background script, but not to AFFECT it in any way (so that it continues to run as if nothing happened after the interruption), why not use an on-keypress script?
I am Srime
Slime
Send private message
 
 PostWed Jan 09, 2013 12:04 am
Send private message Reply with quote
well the main reason was that the on-key-press scripts reacts to any key, and while I had that now in my script for testing purposes, I was thinking to have it bound to specific key's.

the second reason is that I wanted to discover a way to have a script interrupted by another when certain conditions are true, that I could apply to even more than just key's (minutes of play, tags,etc). And that goes without having to constantly make a check in the first script with every command.
edit: and have additional possibilities like exiting the orginal script as well.
Metal Slime
Send private message
 
 PostWed Jan 09, 2013 3:44 am
Send private message Reply with quote
What you are asking for is impossible until we have multi-scripting, or whatever the bosses call it. As of right now, you have to manually check for something anytime you want it possible to be checked for.

Now you can cheat your way out of this slightly by making alternate versions of literally EVERY COMMAND YOU WILL BE USING FOR THESE ANIMATIONS as your own plotscripts, and call those. Something like the following:

Code:
script, new_wait, wait_time, begin
variable(counter)

if(wait_time<<1),then
 (exit script)
for(counter,1,wait_time),do
 begin
  wait(1)
  #whatever checking you need to do
 end
end


But as long as your immediate needs are only to interrupt, I'd recommend using the on-keypress, and have the script that is called contain its own check to see what key was pressed before continuing on to create the interruption.
I am Srime
Metal Slime
Send private message
 
 PostWed Jan 09, 2013 3:49 am
Send private message Reply with quote
Another idea: if you want to have the possibility of having one script 'kill' another one, you could have a global variable that is set to 1, and multiply all arguments in the background script by this global variable when each command is called. Now if you want an interrupting script to 'kill' the background script, have the interrupting script set this global variable to zero. Then you just have to arrange some safeguards:
-make sure NPC 0 is invisible and can't do anything
-make sure textbox 0 is empty and invisible
-what does fightformation(0) do? Might need explicit check here
-what does showbackdrop(0) do? Again, might need explicit check here
-probably some other things I'm not thinking of
I am Srime
Liquid Metal King Slime
Send private message
 
 PostWed Jan 09, 2013 4:36 am
Send private message Reply with quote
score100 wrote:
well the main reason was that the on-key-press scripts reacts to any key, and while I had that now in my script for testing purposes, I was thinking to have it bound to specific key's.


This part is actually pretty easy:

Code:

plotscript, on keypress example, begin
  if(key is pressed(key:A)) then(
     # do something
  )
  if(key is pressed(key:B)) then(
     # do something different
  )
end


score100 wrote:
the second reason is that I wanted to discover a way to have a script interrupted by another when certain conditions are true, that I could apply to even more than just key's (minutes of play, tags,etc). And that goes without having to constantly make a check in the first script with every command.
edit: and have additional possibilities like exiting the orginal script as well.


This is actually possible. msw188 is correct that the future addition of script multitasking will help, but there is a way to fake multitasking with a one-tick timer.

Code:

plotscript, one tick script, begin
  if(check tag(tag:Foo) == ON) then(
    # do something
    set tag(tag:Foo, OFF)
  )

  if(minutes of play == 30 && check tag(tag: 30 minute thingy) == OFF) then(
    # do 30 minute thingy
    set tag(tag: 30 minute thingy, ON) # make sure it only happens once
  )

  # repeat this script on the next tick using timer 0
  set timer(0, 0, 1, @one tick script)
end
Metal Slime
Send private message
 
 PostWed Jan 09, 2013 5:04 am
Send private message Reply with quote
One-tick timers calling scripts! What is this shenaniganry that creates new words for my cry of disbelief??? Next thing you know some clown will appear and start claiming that the word 'slice' can allow enemy sprites to attach to each other outside of battle, rather than simply quenching my thirst in a mediocre fashion.
I am Srime
Liquid Metal King Slime
Send private message
 
 PostWed Jan 09, 2013 4:23 pm
Send private message Reply with quote
Code:

plotscript, some clown, begin
  variable(sl1, sl2)
  sl1 := load large enemy sprite(5)
  sl2 := load large enemy sprite(6)
  set parent(sl2, sl1)
  set slice y(sl2, -80)
end
Display posts from previous:
Page 1, 2  »