Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Jakerpot on Thu 08/01/2009 03:31:24

Title: Scripting problem with "if" expression
Post by: Jakerpot on Thu 08/01/2009 03:31:24
[code]Hi folks, well i'm trying to do a puzzle in my game, that when you look to a hotspot, a object turns invisible (object1.visible=false) and other turns visible (object2.visible= true). And then, when object 2 turns visible, the player can pick it. I used a IF clause, in case that the player try to pick the object when it is invisible. then this is the code:

[Code]
function PaintingR_Interact()
{
oSquare.Visible= false;
oBlacksquare.Visible= true;
Display("Its look like a pixel dropped off the mosaic.");
}

function oBlacksquare_Interact()
{
if (oBlacksquare.Visible = true)
{
   player.AddInventory(iBlacksquare,)
   oBlacksquare.Visible= false
}
else[
}


OBS: PaintingR is the hotspot.
oSquare is object 1.
oBlacksquare is object 2.

Whats my problem?
A error pop up in the screen when trying to save:
room1.asc(57): Error (line 57): Parse error in expr near 'oBlacksquare'

i already tryied anything, but nothing works! What should i do please??
[/code][/code]
Title: Re: Scripting problem with "if" expression
Post by: Creator on Thu 08/01/2009 03:40:14
Your problem is here:


if (oBlacksquare.Visible = true)


It should be:


if (oBlacksquare.Visible == true)


When checking a variable you need a double "=" sign. When setting a variable you only need one.
By the way, if an object is invisible then you can't click on it anyway so I don't see why you need the check in the first place.
Title: Re: Scripting problem with "if" expression
Post by: Jakerpot on Thu 08/01/2009 04:25:04
thanks! thanks! MUCH MORE THANKS!!!! i love you man... (not literaly)
I didn't know that if an object is invisible i couldn't pick it... but ok, i practice my scripting!  :D
thanks again!