making a door with interruption

Started by Mikey, Wed 22/04/2009 21:18:06

Previous topic - Next topic

Mikey

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
}


Mikey

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.

Hudders

Use eBlock to stop the door changing before he gets to the coords:

Code: ags

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

Mikey

#4
Quote from: Hudders on Thu 23/04/2009 09:34:18
Use eBlock to stop the door changing before he gets to the coords:

Code: ags

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.

Khris

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.

Hudders

Ah OK then.

Your if statement should look like this:

Code: ags

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.

Mikey

yeah i tried the exact same thing yesterday with those problems.

Hudders

#8
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:

Code: ags

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

Mikey

Code: ags

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.

Khris

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.

Mikey

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.

Hudders

As a guess, I'd say the x and y coordinates are the wrong way around in the if statement. Should be:

Code: ags

cEgo.x == 70 && cEgo.y == 230

Mikey

yeah i noticed that aswell, that didn't affect anything however.

Hudders

The coordinates are covered by a walkable area, aren't they?

Mikey

what do you mean? is there a walkable area under where the coordinates say? yes there is

thezombiecow

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...

Mikey

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.

thezombiecow

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...

Mikey

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.

SMF spam blocked by CleanTalk