 |
Castle Paradox
|
View previous topic :: View next topic |
Author |
Message |
iamben
Joined: 29 May 2007 Posts: 10 Location: university of virginia
|
Posted: Sun Jul 08, 2007 5:20 pm Post subject: moving two copies of an NPC at one time |
|
|
i have two guards. i want to make them walk. they are both NPC #2, copies 0 and 1. here is my defective script:
Code: |
script, prison, begin
variable (guard A)
set variable (guard A, NPC reference(2,0))
while (1==1) do (
walk NPC (guard A, west, 8)
wait for NPC (guard A)
wait (5)
set NPC direction (guard A, south)
wait (10)
set NPC direction (guard A, east)
wait (5)
walk NPC (guard A, east, 8)
wait for NPC (guard A)
wait (5)
set NPC direction (guard A, south)
wait (10)
set NPC direction (guard A, west)
wait (5)
)
variable (guard B)
set variable (guard B, NPC reference(2,1))
while (2==2) do (
walk NPC (guard B, west, 19)
wait for NPC (guard B)
wait (5)
set NPC direction (guard B, south)
wait (10)
set NPC direction (guard B, east)
wait (5)
walk NPC (guard B, east, 19)
wait for NPC (guard B)
wait (5)
set NPC direction (guard B, south)
wait (10)
set NPC direction (guard B, west)
wait (5)
)
end
|
what is wrong? |
|
Back to top |
|
 |
djfenix

Joined: 12 Mar 2003 Posts: 359
|
Posted: Sun Jul 08, 2007 6:09 pm Post subject: |
|
|
I'm not a great scripter, but my guess is in the wait commands.
Because you're telling the script to "wait for guard A" or whatever, the script will only proceed when Guard A finishes moving. |
|
Back to top |
|
 |
iamben
Joined: 29 May 2007 Posts: 10 Location: university of virginia
|
Posted: Sun Jul 08, 2007 6:45 pm Post subject: |
|
|
i was thinking the same thing. but how do i get them to move simultaneously? it would be easier if they were moving the same distance. |
|
Back to top |
|
 |
Moogle1 Scourge of the Seas Halloween 2006 Creativity Winner


Joined: 15 Jul 2004 Posts: 3377 Location: Seattle, WA
|
Posted: Sun Jul 08, 2007 10:09 pm Post subject: |
|
|
This is significantly easier with the plotscripting syntax in the nightlies, where you can use timers to automate this kind of thing. I'm not certain on the syntax, so here's Ysoft or TMC to tell you how you'd do it. _________________
|
|
Back to top |
|
 |
Bob the Hamster OHRRPGCE Developer

Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
Posted: Mon Jul 09, 2007 8:47 am Post subject: Re: moving two copies of an NPC at one time |
|
|
This is an infinite loop, and I see nothing that breaks out of it-- so the second half of the script can never be reached. |
|
Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Mon Jul 09, 2007 10:30 am Post subject: |
|
|
If you are willing to give up the standing and looking around, this is easy with the pace NPC movement type in custom's map editor. If they are not walking all the way to a wall you can put an inviible step-on NPC where you want them to turn around (NPCs cannot walk on step-on NPCs). Otherwise you will need some pretty ttough code to do this. I don't know how the WIP version's timers work, but going off of the last stable version I think the easiest thing to do would be to have the NPCs on pace type, but to have a loop in the background constantly checking for their position. When one of the NPCs hits its turnaround point, this background loop stops them (sets their speed to zero), then does the turning around bit, but also needs to check the other NPC's position while doing this. If you would like to try this, and need help, just let us know. Or alternatively, if you want to try using the timers, let them (meaning one of the developers like The Mad Cacti) know. _________________ My first completed OHR game, Tales of the New World:
http://castleparadox.com/gamelist-display.php?game=161
This website link is for my funk/rock band, Euphonic Brew:
www.euphonicbrew.com |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Tue Jul 10, 2007 5:59 am Post subject: |
|
|
Running multiple scripts at once won't be a feature until the next-next release. Timers aren't a miracle cure, in this case they only make things slightly easier.
You have 2 unrelated scripts that need to run at once, except only one can run at once. Now in C, this is accomplished with some macro wizardry hiding a switch (coroutines), but in hamsterspeak we have to split one of the scripts up into pieces, either into lots of little scripts, or using a switch statement as I've done here to select the bit of the script you want to run each time you call it.
OK, I've rewritten your code to work as you wanted, but you must use a 'WIP' build of Game.exe AND of Hspeak.exe for these to work. Blame Moogle.
This uses 2 timers: basically the timers ask that the specified script is called in so many tick's time. Timer 0 will call prison2, so set timer (0, 5) causes prison2 to be called in 5 ticks time, and since prison2 state is incremented, it'll run the next part of the script.
Variables will be wiped every time prison2 exits, so I made Guard B a global variable.
Code: | global variable (
1, prison2 state
2, guard B
)
script, prison, begin
variable (guard A)
set variable (guard A, NPC reference(2,0))
# prison2 co-script will run in the background through timers
prison2
walk NPC (guard A, west, 8)
wait for NPC (guard A)
wait (5)
set NPC direction (guard A, south)
wait (10)
set NPC direction (guard A, east)
wait (5)
walk NPC (guard A, east, 8)
wait for NPC (guard A)
wait (5)
set NPC direction (guard A, south)
wait (10)
set NPC direction (guard A, west)
wait (5)
# wait for prison2 to finish, if it hasn't already
while (prison2 state <> 0) do (wait)
end
script, prison2, begin
switch (prison2 state) do (
case (0) do (
set timer (0, 0, 1, @prison2) # set up timer 0 with the correct speed and callback
set timer (1, 0, 1, @prison2 npc waiter) # set up timer 1
set variable (guard B, NPC reference(2,1))
walk NPC (guard B, west, 19)
set timer (1, 1) # wait for NPC (guard B)
)
case (1) do (
set timer (0, 5) # wait(5)
)
case (2) do (
set NPC direction (guard B, south)
set timer (0, 10) # wait(10)
)
case (3) do (
set NPC direction (guard B, east)
set timer (0, 5) # wait(5)
)
case (4) do (
walk NPC (guard B, east, 19)
set timer (1, 1) # wait for NPC (guard B)
)
case (5) do (
set timer (0, 5) # wait(5)
)
case (6) do (
set NPC direction (guard B, south)
set timer (0, 10) # wait(10)
)
case (7) do (
set NPC direction (guard B, west)
set timer (0, 5) # wait(5)
)
case (8) do (
# last case, just reset the state to 0, or you won't be able to run the prison script more than once
prison2 state := 0
exit script
)
)
prison2 state += 1
end
script, prison2 npc waiter, begin
if (npc is walking (guard B)) then (
# continue calling this script each tick until the npc stops
set timer (1, 1)
) else (
# ok, get back to prison2 sequence
prison2
)
end |
_________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
iamben
Joined: 29 May 2007 Posts: 10 Location: university of virginia
|
Posted: Thu Jul 12, 2007 12:18 pm Post subject: |
|
|
thanks, mad cacti, and everyone else.
the script helps me out a great deal...and those timers will come in handy for other scripts, i'm sure
=) |
|
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
|