Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

Trying to activate multiple do blocks at once

 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
Baconlabs
PURPLE IS MANLY




Joined: 15 Mar 2009
Posts: 335
Location: Tennessee

PostPosted: Fri Jun 12, 2009 10:06 pm    Post subject: Trying to activate multiple do blocks at once Reply with quote

In trying to make maps interesting, I want to have many NPCs going through certain paths and animations indefinitely, without the player activating them.
Basically, having each NPC "do its own thing" when the map loads.

So the best way to do this is with the map's Autorun script, right?

With many NPCs doing completely different things, I created several do blocks in this format:
Code:
variable(x)
for (x,1,2,0) do,begin
     [Actions to loop]
end

(The 0, of course, makes the block loop indefinitely.)
The problem is, only the first loop is activating. This is probably because when the loop ends, it jumps back up to the top of the script, preventing the rest of the blocks from starting.

How can I work around this?
Back to top
View user's profile Send private message
Moogle1
Scourge of the Seas
Halloween 2006 Creativity Winner
Halloween 2006 Creativity Winner



Joined: 15 Jul 2004
Posts: 3377
Location: Seattle, WA

PostPosted: Fri Jun 12, 2009 10:07 pm    Post subject: Reply with quote

I suggest using timers instead. What you're doing won't work.
_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address
Baconlabs
PURPLE IS MANLY




Joined: 15 Mar 2009
Posts: 335
Location: Tennessee

PostPosted: Fri Jun 12, 2009 10:18 pm    Post subject: Reply with quote

Okay, the way I'm understanding it...

The Autorun script triggers the timers, something along the lines of:
Code:
set timer(X,18,18,@Loopscript)

Which will cause the looping script (made seperately from the autorun) to activate after one second.

Have I got that right?
Back to top
View user's profile Send private message
Pepsi Ranger
Reality TV Host




Joined: 05 Feb 2003
Posts: 493
Location: South Florida

PostPosted: Sat Jun 13, 2009 2:37 am    Post subject: Reply with quote

Quote:
Okay, the way I'm understanding it...

The Autorun script triggers the timers, something along the lines of:

Code:
set timer(X,18,18,@Loopscript)


Which will cause the looping script (made seperately from the autorun) to activate after one second.

Have I got that right?


You're halfway there. First off, I have a question. Are you trying to use a timer to launch what you originally wanted the autorun to launch? Or are you using the timer to actually control the NPCs?

It looks to me like you're using the timer to run the same script that the autorun was going to run, which sort of defeats the purpose of using the timer.

The great limitation of plotscripting is that only one script can run at a time, which means if you create a do block for your NPCs to do stuff in, they're all gonna have to do stuff within that same do block, otherwise you're only going to get one guy moving and the rest will hang indefinitely.

By using a timer, you can at least plan when certain scripts are supposed to run. Granted, when one timer triggers an action, it'll forcibly pause another current action (my game is full of these instances, unfortunately), so you're still not gonna get the desired results to a tee. But you can at least avoid eternal hangups, which is what you'd face by looping back to the autorun (or to the script you were originally gonna use as an autorun).

Now, assuming that is not your intention and that you are using timers as regulators, then you still don't need to refer back to your looping script because you can loop a timer to itself by repeating the "set timer" line at the end of the script that the timer triggers. You'll just want to set a conditional that can break the timer in case the timer is no longer needed (like if (current map==xx) then( blah blah) conditional when the map changes).

Now to get back to your timer:

Code:
set timer(X,18,18,@Loopscript)


This would actually take 18 seconds to start. You'll want it to look like this if you want it to launch in one second:

Code:
set timer(X,0,18,@Loopscript)


However, if you're attempting advanced NPC automations with timers, you might want to drop the timer down to 5 ticks rather than 18. Some NPCs can cover a lot of ground in 18 ticks.

Hope this helps some.
_________________
Progress Report:

The Adventures of Powerstick Man: Extended Edition

Currently Updating: General sweep of the game world and dialogue boxes. Adding extended maps.

Tightfloss Maiden

Currently Updating: Chapter 2
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Sat Jun 13, 2009 4:34 am    Post subject: Reply with quote

Edit: looks like Pepsi beat me to it.

Quote:
Code:
variable(x)
for (x,1,2,0) do,begin

It's MUCH clearer to write this code like this:
Code:
while (true) do, begin
  ...
end


Baconlabs wrote:
The Autorun script triggers the timers, something along the lines of:
Code:
set timer(X,18,18,@Loopscript)

Which will cause the looping script (made seperately from the autorun) to activate after one second.

Have I got that right?


No, that will trigger after roughly 18 seconds.
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
Baconlabs
PURPLE IS MANLY




Joined: 15 Mar 2009
Posts: 335
Location: Tennessee

PostPosted: Sat Jun 13, 2009 11:12 am    Post subject: Reply with quote

Pepsi Ranger wrote:
The great limitation of plotscripting is that only one script can run at a time

That explains a lot of unexpected freezes that occurred yesterday. A script from the previous map carried over to the current one with the autorun script (fixed that with tags.)

With that being the truth, my original plan will never work. I'll have to take a detour here.
New theory:
Sequence everything within the same autorun plotscript, one action occurring after the other, having NPCs sit around until everything's done, then loop.

Timers, in this situation, seem redundant, so I'm abandoning that idea.
Back to top
View user's profile Send private message
Spoon Weaver




Joined: 18 Nov 2008
Posts: 421
Location: @home

PostPosted: Sat Jun 13, 2009 12:13 pm    Post subject: Reply with quote

Baconlabs wrote:

Sequence everything within the same autorun plotscript, one action occurring after the other

This is what i was going to suggest.

Basically, I would do something like this. First set up a loop script, and for simplicity fill it with smaller scripts. Like this:

Code:
plotscript,loop,begin
    while (true) do, begin
       script1
       script2
       script3
    end
end

then in each smaller script, deal with a certain NPC. like npc 5. Now I'm going to take a guess at what you are looking for, and say you want the NPC's to be walking around at the start. and then when they reach a place of interest they interact.
The places of interest are their own special maptile. I could help you change it to something else, like perhaps an x,y coordinate, but for now i'll do maptile 5.


Code:
script,script1,begin

 variable ( count,villager )
   for ( count,0,NPC copy count (5)--1,1 ) do,begin
     villager:=npc reference( 5,count )

     if,begin
       read map block ( (NPCX(villager),NPCy(villager)==5 )
     end
      then,begin
        change npc id ( villager,6 )
      end

end

end


This changes NPC 5 into NPC 6 when the npc is at map block 5.
Another script would also have to be made to turn NPC 6 back into NPC 5 when it was done doing, whatever. ( Of course, when it's done it might want to turn into another NPC altogether. Like an NPC plus groceries. )

Another script, could be made that controls an NPC. Say to make it perform the task it should be doing at it's location. Such a script would need to; first, change the NPC number on the above script. Then, set a variable, that will keep track of the NPc's progress through it's Task. ( This is assuming that only 1 NPC can perform said task at a time. ) Finally, the script would move the NPC along the task increasing the variable as it goes along till it's done and is "shot out" of the task area and thus the variable should be set back to it's original setting, ready for the next NPC.



These comments are all assuming a lot. To better help with your script I'd have to know more about what you're trying to do exactly. Unless, of course, you've got it figured out already.

Excuse in errors in the above scripts. I didn't test them.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Baconlabs
PURPLE IS MANLY




Joined: 15 Mar 2009
Posts: 335
Location: Tennessee

PostPosted: Sat Jun 13, 2009 1:43 pm    Post subject: Reply with quote

Thanks for those extra scripts, Spoonweaver, but I think I've got it figured out now.

I just tested it, and generally speaking the method I mentioned has been working fine.

Though, I discovered two problems in this process.

1) The Run key (an on-keypress script) interferes with whatever's already running, which I overlooked. I am sad to say that the Run and Jump features will no longer be present in NPC-heavy towns.

2) The player stepping in front of a walking NPC will cause its movement to end prematurely, screwing up that NPC's actions until the map is reloaded. I had assumed that the "wait for NPC" command couldn't be interrupted this way and I was wrong.

The latter is going to cause some headaches; I've alleviated it a bit by suspending obstructions and forcing all NPCs to not face the player when activated, but problems can still occur. I suspect this is an inevitability that cannot be prevented.
Back to top
View user's profile Send private message
Pepsi Ranger
Reality TV Host




Joined: 05 Feb 2003
Posts: 493
Location: South Florida

PostPosted: Sat Jun 13, 2009 6:00 pm    Post subject: Reply with quote

Personally, I wouldn't scrap all your ideas. One day in the near to distant future, TMC will implement script multitasking. Right now it's nothing more than a myth--a legend that people speak of to garner hope for a better gaming future, like Duke Nukem Forever. The difference is that unlike said myth, script multitasking will happen. Someday. Maybe even soon. Maybe even sooner now that TMC can see the games requiring it stacking up.

The moral of the story is that sooner or later the idea you had in your head initially will become more achievable (I think) once this is implemented, and it's on his to-do list, so I wouldn't scrap it yet. Just move on to simpler pastures for now and come back to this once multitasking is available. If your game is as big as it appears to be, my feeling is that the feature will be implemented before you're at a point of release.

But we'll wait for TMC to confirm or dispel this theory. Ultimately, you should plan based on what he knows of the situation.
_________________
Progress Report:

The Adventures of Powerstick Man: Extended Edition

Currently Updating: General sweep of the game world and dialogue boxes. Adding extended maps.

Tightfloss Maiden

Currently Updating: Chapter 2
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Baconlabs
PURPLE IS MANLY




Joined: 15 Mar 2009
Posts: 335
Location: Tennessee

PostPosted: Sat Jun 13, 2009 7:26 pm    Post subject: Reply with quote

Pepsi Ranger wrote:
One day in the near to distant future, TMC will implement script multitasking.


Well, that's nice to hear. Indeed, this game (Viridia for those not in the know) is quite large, and the first demo is still some number of months away, covering a little less than a third of the game. The entire thing will take years, probably.

I've been fiddling the OHRRPGCE since Quaternion (2005), and I'm very much impressed with its progress over the years. Who know what all will change in a single year?

I'll take your advice for now and keep some things on the backburner.
Back to top
View user's profile Send private message
Spoon Weaver




Joined: 18 Nov 2008
Posts: 421
Location: @home

PostPosted: Sat Jun 13, 2009 8:00 pm    Post subject: Reply with quote

Quote:
1) The Run key (an on-keypress script) interferes with whatever's already running, which I overlooked. I am sad to say that the Run and Jump features will no longer be present in NPC-heavy towns.

2) The player stepping in front of a walking NPC will cause its movement to end prematurely, screwing up that NPC's actions until the map is reloaded. I had assumed that the "wait for NPC" command couldn't be interrupted this way and I was wrong.



1)You can still run and jump while using almost the same scripts.
Here's how!
First, find your loop script. Then add, somewhere in the loop, a the statement
If (key is pressed=="run key") then (running script)
The same goes for the jumping script

2) Not exactly sure how to go about fixing this for you since I assume it would take serious reworking. But, you could use my method of maptile activation, with added steps to the walk npc direction script( like hundreds of steps ) and then just stop the npc when they arrive. This could be used to change the NPCs direction whenever you wanted, and if someone got in his way he'd just continue trying to go about his business. Another, neat trick might be to add a script after the walking so that if the steps do in fact run out, ( even though there's a hundred ) a textbox appears with the NPc asking you to move, and then activates the npc again.

Hope this makes since.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
msw188




Joined: 02 Jul 2003
Posts: 1041

PostPosted: Sun Jun 14, 2009 1:32 pm    Post subject: Reply with quote

If the player is disrupting NPCs walking, just use a command like:

[conceptual pseudocode]
Code:
while(npcx(who)<<8, and, "some kind of check that the NPC is currently trying to walk, not scratch his chin"),do
 (walknpctox(who,8))


This can be put in the master map loop that is running everything and checking for where all the NPCs are and what they're doing at the moment. I haven't used timers, but that method seems fishy to me, for exactly the kinds of reasons that you're describing. How can we be sure that it will take the same number of ticks for an NPC to reach its destination when there's the chance that the player will interfere? I think the best thing is to have the master map loop contain a whole bunch of 'if' commands regarding the actions of all your animating NPCs. As for timing animations, use local variables to count how long an NPC is in a certain pose, incrementing on each master loop, rather than having single loops for each NPC.

As for running and jumping, they shouldn't really interfere with the master loop unless there are some serious wait commands involved. In fact, they could probably just be inserted into the main map loop to avoid having a keypress script doing any kind of interrupting. The main map loop is going to have to run every tick anyway, so just insert a
Code:
if(key is pressed (running key)),then
 (setherospeed(me,10))
else
 (setherospeed(me,4))

within that loop. I can't remember the exact commands for those, but that's the idea (you may need something with keyval instead of keyispressed). Put the jumping script in the main loop as well, and as long as there are no significantly long wait times in there, the worst that will happen is that some NPC animations will freeze during a jump. If you handle walking the way I suggested earlier, that shouldn't be affected.
_________________
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
View user's profile Send private message Visit poster's website
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Mon Jun 15, 2009 6:47 am    Post subject: Reply with quote

Pepsi Ranger wrote:
Personally, I wouldn't scrap all your ideas. One day in the near to distant future, TMC will implement script multitasking. Right now it's nothing more than a myth--a legend that people speak of to garner hope for a better gaming future, like Duke Nukem Forever. The difference is that unlike said myth, script multitasking will happen. Someday. Maybe even soon. Maybe even sooner now that TMC can see the games requiring it stacking up.


OK, FINE! I'll work on the new interpreter right now!

An experimental version of the new interpreter already exists, and the multitasking features are well planned, so this is probably not doomed to stall. However, I'm doing 6 things at once at the moment, and will start another 6 when I get the chance. I'm aiming to have some kind of partially working version within a few months.


If you avoid all wait commands, you can do any number of things at once, but writing scripts like this is very annoying. You shouldn't have to disable jumping and running because of the NPC scripts.

On the other hand, if you use timers, you can allow one script (such as jumping) to contain waits, and the others can continue to be triggered each tick by a timer. The cleanest way to use timers to write complicated script is either with a state machine (this is maybe similar to what msw meant), or to split the script up into tiny pieces. Here's the former, with the start up code omitted:

Code:

global variable (100, npc pathing state)
global variable (101, wandering npc)

script, npc path, begin
 if (current map <> 99) then (exit script)
 set timer (1, 0) # restart the timer, to trigger next tick again
 switch (npc pathing state) do (
  case (0) do (
   # head to X = 6
   if (npc x (wandering npc) << 8) then (
    if (not (npc is walking (wandering npc))) then (
     walk npc to x(wandering npc, 8)
    )
   ) else (npc pathing state := 1)
  )
  case (1) do (
   # wait 10 ticks
   set timer (1, 9)
   npc pathing state := 2
  )
  case (2) do (
   set npc direction (wandering npc, north)
   npc pathing state := 3
  )
  #and so on...
 )
end


(I can't remember if the 'npc is walking' check is necessary)
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
Guest







PostPosted: Mon Jun 15, 2009 10:51 am    Post subject: Reply with quote

I've never bothered checking whether or not the NPC was walking in that scenario, and never had any problems.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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