Hey guys, I am currently trying to enable a cupboard to be opened when the player presses on the object. However, I keep getting the error below:
room2.asc(35): Error (line 35): 'ob1' is a global var; cannot use as name for local
If anyone could help me fix this issue that would be really good :grin:
//Code in GlobalScript.asc
function VisibleSwitch(Object* oCupboardClosed, Object* oCupboardOpen)
{if ((ob1.Visible == true) && (ob2.Visible == false)) {
ob1.Visible = false;
ob2.Visible = true;
} else if ((ob1.Visible == false) && (ob2.Visible == true)) {
ob1.Visible = true;
ob2.Visible = false;
}
}
Objects used in the Global must use their Object ID NOT what you have called them.
Eg:
ob1.Visible = true; // Will bring up an error in Global.
object[1].Visible=true; // Acceptable in Global.
1. Something else is also called "ob1", however you don't need to refer to that in your code.
2. This function is in the global script, which means you can only refer to room objects using the object[] array.
3. In line 2 you're supposed to use general names for the parameters; the specific objects are used when the function is called.
// Globalscript.ash
import function VisibleSwitch(Object *a, Object *b);
// GlobalScript.asc
function VisibleSwitch(Object *a, Object *b) {
a.Visible = !a.Visible;
b.Visible = !b.Visible;
}
// Room script
function cupboard_Interact() {
VisibleSwitch(oCupboardClosed, oCupboardOpen);
}
Now enter "cupboard_Interact" for both objects next to "interact with object".
Edit: fixed last function
@Khris; I entered the code into their respective scripts but when doing the room script it came up with the following error below.
Failed to save room room2.crm; details below
room2.asc(37): Error (line 37): Unexpected '{'
// Room script
function cupboard_Interact;
{
VisibleSwitch(oCupboardClosed, oCupboardOpen);
}
You have a semi-colon at the end of line 2, remove it.
Not only that, but also the missing parentheses:
function cupboard_Interact()
Whoops, sorry, thanks. Fixed the code.
The good news is that no more errors are popping up :grin:
However, the bad news is that when I interact with either door they both disappear and don't come back.
You have to turn one of them invisible at the start of the game obviously, all my code does is toggle both objects' visibility. (Yours wouldn't have worked either though.)
Just add the room's before fadein event and in there set oCupboardOpen.Visible to false.
It's working great now, thanks for the help Khris, Slasher and Iceboty V7000a. :-D