So, in my project, the player doesn't change screens by walking off them, but rather thru a travel hud that pops up.. as illustrated here:
(http://www.wayneadams.net/stuffola/AGS_Stuff/bugs/travel1.jpg)
Say north takes you from room one to room two, you click north:
and
(http://www.wayneadams.net/stuffola/AGS_Stuff/bugs/travel2.jpg)
Room 2.. obviously..
now I'm handling this in the global script like so:
#sectionstart GO_NORTH_Click
function GO_NORTH_Click(int interface, int button)
{
if (player.Room == 1)
gTravel_menu.Visible = false;
player.ChangeRoom(2);
}
#sectionend GO_NORTH_Click
this works.. until i need the player to be able to go back or to another room...etc.. if i have multiple IF statements in the global GO_NORTH_Click function, AGS gets upset and tells me this:
code with multiple IF statements:
#sectionstart GO_NORTH_Click
function GO_NORTH_Click(int interface, int button)
{
if (player.Room == 1)
gTravel_menu.Visible = false;
player.ChangeRoom(2);
if (player.Room == 2)
gTravel_menu.Visible = false;
player.ChangeRoom(1);
}
#sectionend GO_NORTH_Click
error:
(http://www.wayneadams.net/stuffola/AGS_Stuff/bugs/travel3.jpg)
I know I'm doing this wrong, but i can not for the life of me figure out how to write this function..
Any help is much appreciated..
Thanks in advance
I haven't checked details of this post, but one obvious cause of your error is because you did not write if clauses with multiple lines onf content correctly (Even the single 'if' version was not actually correct). So:
#sectionstart GO_NORTH_Click
function GO_NORTH_Click(int interface, int button)
{
if (player.Room == 1) {
gTravel_menu.Visible = false;
player.ChangeRoom(2);
}
}
#sectionend GO_NORTH_Click
and
#sectionstart GO_NORTH_Click
function GO_NORTH_Click(int interface, int button)
{
if (player.Room == 1) {
gTravel_menu.Visible = false;
player.ChangeRoom(2);
}
if (player.Room == 2) {
gTravel_menu.Visible = false;
player.ChangeRoom(1);
}
}
#sectionend GO_NORTH_Click
You may even drop in an 'else' if you like, but apart from readibility of the codes the result is the same in your case:
#sectionstart GO_NORTH_Click
function GO_NORTH_Click(int interface, int button)
{
if (player.Room == 1) {
gTravel_menu.Visible = false;
player.ChangeRoom(2);
} else if (player.Room == 2) {
gTravel_menu.Visible = false;
player.ChangeRoom(1);
}
}
#sectionend GO_NORTH_Click
I'll reformat my function to that structure.. i knew it was matter of inncorrect code grammar, i just didn't know how it should be laid out..
Thanks for a quick reply, Gilbet.
EDIT: That is in fact what i was doing wrong, all works well now..
Gilbet, you get one piece of triforce for the assist. Thanks a bunch!
Easy rule of thumb is just to always put brackets, even if you just have one command to call.
~Trent
If you're going to have a lot of rooms, you might consider using custom properties:
Add one for each direction, type int, name "north", "west", etc., default value 0.
Use one function to handle all four buttons, then check for the button's ID to determine which one was clicked:
function GO_DIR_Click(GUIControl *control, MouseButton button) {
if (button != eMouseLeft) return; // only process left-clicks
int d;
if (control.ID == 0) d = GetRoomProperty("north"); // north button's ID is 0
if (control.ID == 1) d = GetRoomProperty("west");
...
if (d > 0) player.ChangeRoom(d);
else {
// handle exceptions here
if (player.Room == 5) {
if (boulder_destroyed) player.ChangeRoom(7);
else player.Say("There's a boulder blocking the way north.");
}
}
}
Now you can simply enter the adjacent room numbers for each room / leave them set to zero if the player can't always go there.
I just noticed that the parameters are "int interface, int button" in your function?
You're using the old 2.72, but still the parameters of a button's Click function should be "GUIControl *control, MouseButton button";
yours were used in the even then obsolete interface_click function.
Im gonna see about integrating that into my code after work today. Thanks man..
Snap.. forgot.. my copy of Street Fighter 4 comes in today..
Maybe I'll write it in tomorrow. :)