Non-blocking walks for dummies? [SOLVED]

Started by Dooie, Tue 15/04/2008 14:59:00

Previous topic - Next topic

Dooie

I've started working with AGS a while ago, and so far I've been able to figure everything out by looking around on this forum and searching the tutorials. But now I have a little problem with a floor switch that I can't seem to solve, and I don't know where to look.

My room has a floor switch that stays pressed down as long as you stand on it, and releases when you walk off it. So I made a region above the floor tile with these interactions:

// script for Region 1: Player walks onto region

object[7].SetPosition(239, 113);                     // I'm using retro 8-bit graphics so thats why I used SetPosition
                                                                        // instead of SetView; the switch is basically a floor tile raised one pixel.
PlaySound(2);                                                 // Click!
dialog[0].SetOptionState(3, eOptionOn);       // A dialog option to ask an NPC to stand on the tile is also enabled.

// script for Region 1: Player walks off region
 
  object[7].SetPosition(240, 112);
  PlaySound(1);

(by the way, how do I place script text in a window when posting on this forum?)
So far so good. The button doesn't actually do anything else yet, but that's not the point (I'm still figuring out the basics of scripting). Now, when I talk to the NPC while standing on the button, the player character walks to the NPC before starting the dialog, and the button remains pressed down because player.Walk is blocking (otherwise my pal would start talking right away, right?). I found some info that might be related under the tutorial topic 'Understanding Blocking Functions', but I still don't quite understand. I think I have to put something in repeatedly_execute or repeatedly_execute_always but I'm not sure what. Thanks in advance!

I'm still using 2.72, by the way. Want to learn all the basics first before I do away entirely with the interaction editor.

SSH

Firstly, use [ code ] ... [ /code ] to put stuff in a code block.

Secondly, the general solution as to "walk-tos" being blocking is to do a bit of scripting in your on_click function so that the game remembers that you are walking somewhere for a reason, even though you do it non-blocking and then runs the processclick after you've stopped moving with your non-blocking walk.
12

Dooie

Thanks, but you're still going a little too fast for me. Ok, so there is a command or set of commands that tells my guy to wait until he's finished walking before starting the next command, even though his walk is non-blocking. But which code, and where exactly do I put it? And will it work for the rest of the room (i.e. when I do anything else the switch also gets released when I step off it?)

Dooie

Ok, seeing how nobody has answered yet, this must be a really stupid question or something. Still, it would really help if someone could give me a nudge in the right direction. What 'bit of scripting' do I have to do? I also found Bernie's NoBlock module, but I don't understand exactly how to use it or modules in genera for that matter (yes, I read the readme). Any bit of help/advice is deeply appreciated!

Matti

#4
I don't know much about blocking-functions but a simple way (to avoid modifying the blocking status) would be to execute your little region 1-script when talking to the character.

Before starting the dialog, run the same script as when the character leaves the region:

object[7].SetPosition(240, 112);
PlaySound(1);
Run_dialog ....

Pumaman

There are two ways to handle this:

(1) leave the walk blocking and use a workaround like matti has suggested (you could also put some code in the room repeatedly_execute_always to call Region.GetAtRoomXY and effectively implement the Walks Off Region feature manually)

(2) make the walk non-blocking. To do this, when the player clicks on the NPC you'd just call player.Walk with eNoBlock, and set a variable to record the fact that they're on the way to speak to the NPC. Something like:

(at top of script)
bool walkingToNpc;

(when clicking on NPC)
player.Walk(blah, blah, eNoBlock);
walkingToNpc = true;

(in repeatedly_execute)
if ((!player.Moving) && (walkingToNpc))
{
  walkingToNpc = false;
  dNpcDialog.Start();
}

Dooie

Cool, thanks matti and pumaman! I think I can actually figure this out.  ;D
I'll try it out this week and let you know how it turns out!

Dooie

Works like a charm!

But if I understand correctly, do I have to declare a new bool variable for every action on every object/hotspot/character if I want the walk to be non-blocking? I guess that's what the module is for right?

And consequently, all those interactions will actually have to be scripted under repeatedly_execute? In that case, I think I'm beginning to understand why the interaction editor was removed in 3.0...

Anyway, thanks for helping me out!
Dooie

Pumaman

If you want to design your game to have an interface whereby the norm is that interactions do a non-blocking walk, you can code something into the global script to handle it, so that you don't have to keep doing this. The code we've suggested is meant as a hack for one particular situation where you need this to happen.

The scripting to do it globally is more complex, but the basic idea would be that in the global script on_mouse_click function, you find out what hotspot/object/character the player has clicked on, then set a variable to remember it, and then have the walking code just once in the global script. In the global script rep_exec, you'd then call the appropriate RunInteraction function when the walk finished.

If all that seemed a bit overwhelming, leave it for now and come back to it when you've got some more experience :)

Dooie

#9
Thanks, yeah, I've gotten a lot further. I think I have enough experience now to complete a simple one- or two room game, albeit with some clumsy workarounds.

For now, I'm just going to change all those bools to a single int, so I can just use a different number for every action, and 0 for no action, and so the interactions will be easy cancellable.

I'll be back! (but not before I RTFM with my fancy new knowledge!)

SMF spam blocked by CleanTalk