Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Mikey on Wed 22/04/2009 21:18:06

Title: making a door with interruption
Post by: Mikey on Wed 22/04/2009 21:18:06
I am using the verbcoin template.
i have made a door with the following script which works fine with an eblock put in but what i want is for when i click interact with door, i do not want the player to not be able to move until it gets to the door and opens/closes it. i thought about having the game check to see if the character is on the coordinates it was asked to go to before performing the change but i do not know how to get the players coordinates.

function closeddoor_Interact()
{
cEgo.Walk(70, 230);
if  (int cEgo.y = 70 && int cEgo.x = 230)= true;

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
this line i know is wrong but can someone please tell me what i should put instead, it really is just a random guess i tried but hopefully you can see what i am trying to do.

closeddoor.Visible = false;
opendoor.Visible = true;

else do nothing bla bla bla
}
Title: Re: making a door with interuption
Post by: Khris on Wed 22/04/2009 22:48:38
I've coded a small module to achieve this:

http://www.adventuregamestudio.co.uk/yabb/index.php?topic=36383.msg477380#msg477380
Title: Re: making a door with interuption
Post by: Mikey on Thu 23/04/2009 01:51:29
thanks for that but i am using the verbcoin template so importing that module stops my verbcoin from appearing. Thanks anyway. do you know if there is a way i can still do it by doing something like asking if my character has reached the coordinates before performing the action somehow, like i tried in my first post.
Title: Re: making a door with interuption
Post by: Hudders on Thu 23/04/2009 09:34:18
Use eBlock to stop the door changing before he gets to the coords:


function closeddoor_Interact()
{
cEgo.Walk(70,  230, eBlock);
closeddoor.Visible = false;
opendoor.Visible = true;
}
Title: Re: making a door with interuption
Post by: Mikey on Thu 23/04/2009 12:21:00
Quote from: Hudders on Thu 23/04/2009 09:34:18
Use eBlock to stop the door changing before he gets to the coords:


function closeddoor_Interact()
{
cEgo.Walk(70,  230, eBlock);
closeddoor.Visible = false;
opendoor.Visible = true;
}


erm ye it works with an eblock but what i said was i don't want him to just go straight there without having a choice of clicking away from it if the player changes his mind as he is walking.
Title: Re: making a door with interuption
Post by: Khris on Thu 23/04/2009 12:29:56
Yeah, my module assumes a standard game.
I'd have to look into the verbcoin template to make them work together but I'm quite busy right now, sorry.
Title: Re: making a door with interuption
Post by: Hudders on Thu 23/04/2009 12:49:29
Ah OK then.

Your if statement should look like this:


if  (cEgo.y == 70 && cEgo.x == 230)
{
closeddoor.Visible = false;
opendoor.Visible = true;
}


(I'm assuming that "&&" is the correct syntax for "and" but I'm not entirely sure about that)

You'd also have to put it in the repeatedly_execute function otherwise it's only going to parse the code at the start of the character's walk, (unless you put in an eBlock, but as you said - that would defeat the object of the exercise). Of course this also means that the door will open when he stands on that spot whether he's been told to open the door or not.
Title: Re: making a door with interuption
Post by: Mikey on Thu 23/04/2009 12:59:25
yeah i tried the exact same thing yesterday with those problems.
Title: Re: making a door with interuption
Post by: Hudders on Thu 23/04/2009 13:15:09
It's clunky, but you could set a variable when you click on the door which is then unset if you click anywhere else.

EG:


function repeatedly_execute()
if  (cEgo.y == 70 && cEgo.x == 230 && varX == 1)
{
closeddoor.Visible = false;
opendoor.Visible = true;
}

...

function on_mouse_click(Mousebutton eMouseLeft)
if (object.getatscreenXY(mouse.x,mouse.y) == closeddoor)
{
varX = 1;
}
else
{
varX = 0;
}


Something like that anyway. I'm a bit hit and miss when it comes to typing the code outside of the application.  :P
Title: Re: making a door with interuption
Post by: Mikey on Thu 23/04/2009 19:06:03

int door = 0;

function on_mouse_click(MouseButton MouseLeft){
if (Object.GetAtScreenXY(mouse.x,mouse.y) == closeddoor){
door = 1;
}
else
{
door = 0;
}
}

function closeddoor_Interact(){
cEgo.Walk(70,230);
}

function repeatedly_execute(){
if  (cEgo.y == 70 && cEgo.x == 230 && door == 1)
{
RestoreWalkableArea(2);
region[1].Enabled = true;
closeddoor.Visible = false;
opendoor.Visible = true;}
}

ok so i entered this and when i click interact with door my character just walks towards it and then stops at the coordinates but the door does not open or any of the other things like restorewalkablearea and region enabled.

Can you see if i have missed anything?

Could it be because i am using a verbcoin template and therefor isn't a click but a release of somekind? thanks for your help so far hudders.
Title: Re: making a door with interuption
Post by: Khris on Thu 23/04/2009 19:57:16
Doing it this way for every interactable hotspot is just crazy.
I'm not sure I'll get around to expanding my module soon though.
Title: Re: making a door with interuption
Post by: Mikey on Thu 23/04/2009 21:03:22
haha yeah my script would be huge, i'm just going to do the game normally for now (with eblock) and change things when i figure out how.I don't know a hell of alot of script but things like this kind of annoy me for some reason.Thanks anyways.
Title: Re: making a door with interuption
Post by: Hudders on Thu 23/04/2009 21:37:54
As a guess, I'd say the x and y coordinates are the wrong way around in the if statement. Should be:


cEgo.x == 70 && cEgo.y == 230
Title: Re: making a door with interuption
Post by: Mikey on Thu 23/04/2009 22:32:22
yeah i noticed that aswell, that didn't affect anything however.
Title: Re: making a door with interuption
Post by: Hudders on Thu 23/04/2009 22:38:19
The coordinates are covered by a walkable area, aren't they?
Title: Re: making a door with interuption
Post by: Mikey on Thu 23/04/2009 23:51:15
what do you mean? is there a walkable area under where the coordinates say? yes there is
Title: Re: making a door with interuption
Post by: thezombiecow on Fri 24/04/2009 10:01:21
What happens if you set door to 1 here:
Quote
function closeddoor_Interact(){
cEgo.Walk(70,230);
door = 1;
}

?

Also, where are you defining int door? Is that at the top of the GlobalScript, or set up through Global Variables? Make sure it's not getting reset to 0 every tick somewhere...
Title: Re: making a door with interuption
Post by: Mikey on Fri 24/04/2009 12:42:50
if i did that it would set the door to 1 and then if i clicked somewhere else it would stay at 1. i defined door at the top of the room script.
Title: Re: making a door with interuption
Post by: thezombiecow on Fri 24/04/2009 12:49:32
Quotei defined door at the top of the room script.

Aah, well I think that's possibly your problem - I'm not in front of AGS so I can't check, but it might keep on getting reset to 0 every tick...?

Try using a Global Variable, and see what difference that makes...
Title: Re: making a door with interuption
Post by: Mikey on Fri 24/04/2009 13:29:28
ok so i put int door = 0; at the top of the global script instead of the room script and it comes up with error undefined token door. i checked the spelling :P don't really know why it is displaying the error.
Title: Re: making a door with interuption
Post by: Hudders on Fri 24/04/2009 13:32:52
It's because you haven't defined

int door;

in the global script.
Title: Re: making a door with interuption
Post by: thezombiecow on Fri 24/04/2009 14:10:39
Define door as a global int in the GlobalVariables section in the right panel...
Title: Re: making a door with interuption
Post by: Trent R on Fri 24/04/2009 16:38:15
Not global script, he's talking about the Global Variables pane that can be found in the Tree on the right (or left) of the editor.

But I'm wondering why you're being told to even do that. Do you use door in any other room? If not, just keep it at the top of your room script.

~Trent
Title: Re: making a door with interuption
Post by: thezombiecow on Fri 24/04/2009 16:42:22
QuoteBut I'm wondering why you're being told to even do that. Do you use door in any other room? If not, just keep it at the top of your room script.

I was only really suggesting it as a quck test to see if setting it at the top of the room script is somehow continually resetting it to 0...

I'm not in front of AGS, so I can't test this end. I wasn't expecting it to turn into a big thing. ;)
Title: Re: making a door with interuption
Post by: Trent R on Fri 24/04/2009 17:01:49
IIRC, defining at the top outside of any function should make it that value and keep it that way. Such a thing might come up if the room# was above 300 (ie. won't save the state of the room).

PS-Didn't mean to bash you, I understand what you're saying now. :) Friends?

~Trent
Title: Re: making a door with interuption
Post by: thezombiecow on Fri 24/04/2009 17:04:04
QuoteFriends?

Of course! ;)
Title: Re: making a door with interuption
Post by: Mikey on Fri 24/04/2009 20:34:12
lol only just realised there was a page 2. ye i defined it as int door in the global variales but that still didn't affect it. COME ON GUYS PUT YOUR HEADS TOGETHER  :P

what is happening so far is the character walks to the door and just stands on the set coordinates and doesn't open it. I would upload a rar of it if you guys are up for messin' around to see what is wrong.
Title: Re: making a door with interruption
Post by: Trent R on Sat 25/04/2009 03:08:48
Assuming your code is still the same as this post (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=37562.msg493892#msg493892)... You have two problems.

1) You're checking the wrong coordinates, Hudders already mentioned this. (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=37562.msg493915#msg493915)

2) door variable doesn't equal 1, thezombiecow mentioned this. (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=37562.msg494041#msg494041)


So what's the problem?

~Trent
Title: Re: making a door with interruption
Post by: Sephiroth on Sat 25/04/2009 03:39:05
Hi,

Maybe you could use something like this:

If there's some kind of Player.IsStandingOnHotspot(hotspot_id) then replace the if statement with it. Or you'll have to use "top, left, bottom, right" with room coords to create a hotpsot.



function door_interact()
{
if(Player.x >= left  && Player.x <= right && Player.y >= top && player.y <= bottom)
{
   Door1.visible = false;
   Door2.visible = true;
   Wait(10);
   Player.ChangeRoom(7);
}
else
{
  Player.Walk(X,Y,eNoBlock); //X and Y are room coords inside the hotspot
}
}



This way the player will start walking to the door and will only open it when he uses interact while standing on the hotspot.The only problem is that you'll have to click one time to get to it and once more to open it. Or just one time if you're already standing there.
Title: Re: making a door with interruption
Post by: Mikey on Sat 25/04/2009 18:39:23
Quote from: Trent R on Sat 25/04/2009 03:08:48
Assuming your code is still the same as this post (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=37562.msg493892#msg493892)... You have two problems.

1) You're checking the wrong coordinates, Hudders already mentioned this. (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=37562.msg493915#msg493915)

2) door variable doesn't equal 1, thezombiecow mentioned this. (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=37562.msg494041#msg494041)


So what's the problem?

~Trent

yeah i replied to both those posts saying yes i already have changed them to the correct script like i already changed the x and y around and what about the door not equaling 1? the variable default is set to 0 at start and is supposed to be changed when clicked interact on the door and changed back to 0 when i click elsewhere.

The problem is i want the character to be able to select interact with the door without the eblock causing the mouse to disappear and the character not to be able to cancel the interact with door action while walking towards it. Now the character just walks towards it stands on the coordinates and doesn't do anything.
Quote
Hi,

Maybe you could use something like this:

If there's some kind of Player.IsStandingOnHotspot(hotspot_id) then replace the if statement with it. Or you'll have to use "top, left, bottom, right" with room coords to create a hotpsot.

Code:


function door_interact()
{
if(Player.x >= left  && Player.x <= right && Player.y >= top && player.y <= bottom)
{
   Door1.visible = false;
   Door2.visible = true;
   Wait(10);
   Player.ChangeRoom(7);
}
else
{
  Player.Walk(X,Y,eNoBlock); //X and Y are room coords inside the hotspot
}
}


This way the player will start walking to the door and will only open it when he uses interact while standing on the hotspot.The only problem is that you'll have to click one time to get to it and once more to open it. Or just one time if you're already standing there.

Hi
That would be almost as lame as the mouse disappearing with the eblock. Thanks anyway though. I think i am going to just make my game normally with the eblock and hopefully someone makes a module for the verbcoin gui later on *cough* khris ;)
But yeah don't worry about it because it looks like as thingymebob said it would be crazy as the code would get really big and messy.Thanks anyway people.
Title: Re: making a door with interruption
Post by: Trent R on Sat 25/04/2009 20:51:43
I haven't looked at Khris's code, but it'd definitely be the best solution.

Another idea, but would create some quirky behaviour, is to add something to the on_mouse_click like if (player.Moving) player.StopMoving();

But, that would probably create more confusion for the player than it would solve.



~Trent