Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Fonda on Fri 27/08/2010 10:02:08

Title: problem to solve - hotspot/object visibility
Post by: Fonda on Fri 27/08/2010 10:02:08
hi dudes, my english isn't very good, but I will explain you my problem anyway.

I have 2 rooms.
In room 1 there is an object (oSomething), that I can pick up ( after picking up this object disappears and an inventoryitem (iSomething) appears in my inventory), trivial.
In room 2, there is a hotspot/object, that has to be invisible/disabled until I didn't pick up oSomething (in room 1) or I have iSomething in my inventory.

my attempt at a solution would be:

function room_Load() //room2 script
{
if (player.HasInventory(iSomething) && // oSomething in room 1 is still visible){

    oBjectInRoom2.Visible=false;
    }



an other problem I have is to make a hotspot enabled, if I have all three items in my inventory, but it works just with some reservations using this scripting:

if (player.HasInventory(iItem1) && player.HasInventory(iItem2) && player.HasInventory(iItem))
    {
    hHotspot.Enabled=true;
    }
   
      else
      {
      hHotspot.Enabled=false;
      }


thanks for reading and I would be glad about a helping answer
Title: Re: problem to solve - hotspot/object visibility
Post by: Matti on Fri 27/08/2010 10:15:42
Use a variable like this:

Pseudo-

bool objectpick=false;

// picking up object in room 1

objectpick=true;

//in the room_load of room 2

if (objectpick) oObject.Visible=false;


Of course objectpick got to be a global variable, since both rooms use it.
Title: Re: problem to solve - hotspot/object visibility
Post by: Khris on Fri 27/08/2010 11:10:48
Regarding the second issue, where did you put that code and when do you want the hotspot's condition to be updated?

What reservations are you talking about? Please be as clear as possible about what you want, what does work and what doesn't work.
Title: Re: problem to solve - hotspot/object visibility
Post by: Fonda on Fri 27/08/2010 11:43:52
Quote from: Khris on Fri 27/08/2010 11:10:48
Regarding the second issue, where did you put that code and when do you want the hotspot's condition to be updated?

What reservations are you talking about? Please be as clear as possible about what you want, what does work and what doesn't work.

the second one is in the same room_load as the first one I extended with "else if" and the problem is, that sometimes the hotspot appears by having only two items, sometimes it works correctly, I suppose, it depends on the order of picking up the items, I dunno.
Title: Re: problem to solve - hotspot/object visibility
Post by: Fonda on Fri 27/08/2010 12:15:48
Quote from: Mr. Matti on Fri 27/08/2010 10:15:42
Use a variable like this:

Pseudo-

bool objectpick=false;

// picking up object in room 1

objectpick=true;

//in the room_load of room 2

if (objectpick) oObject.Visible=false;



Of course objectpick got to be a global variable, since both rooms use it.

I tried it and I got an Error-message: "undefined token objectpick"

bool objectpick=false; (globalscript)
objectpick=true; (added to the function where I do pick up the object)
if (objectpick) oObject.Visible=false; (room-load of the second room)

I assume, I have to define a function with "bool objectpick=false;" in globalscript, but I dont know how to handle with :(
Title: Re: problem to solve - hotspot/object visibility
Post by: Khris on Fri 27/08/2010 12:34:15
You can define global variables in the editor pane by the same name.
Add a new variable, type "bool", name "objectpick", initial value "false".

This line:
  if (player.HasInventory(iItem1) && player.HasInventory(iItem2) && player.HasInventory(iItem))
is correct and everything inside the brackets after it will only be executed if the player indeed has got at least one of each of the three.

Btw, you can change the names of all the game objects (hotspots, inventoryitems, characters, etc.) in their properties pane. iItem1, iItem2 and iItem aren't exactly practical names. Maybe you're confusing the names and according in-game item graphics?
Title: Re: problem to solve - hotspot/object visibility
Post by: Fonda on Fri 27/08/2010 12:57:47
//You can define global variables in the editor pane by the same name.
//Add a new variable, type "bool", name "objectpick", initial value "false".

could you give me an example, Im a very noob on scripting


//This line:
//  if (player.HasInventory(iItem1) && player.HasInventory(iItem2) && player.HasInventory(iItem))
//is correct and everything inside the brackets after it will only be executed if the player indeed has got at least one of
//each of the three.

my intention was to enable a hotspot only if there are all three items activated in my inventory, probably there is an other possibility to achieve the desired  result

//Btw, you can change the names of all the game objects (hotspots, inventoryitems, characters, etc.) in their properties
//pane. iItem1, iItem2 and iItem aren't exactly practical names. Maybe you're confusing the names and according in-game
//item graphics?

I already did it, iItem1 etc are not the names I used in my game :)
Title: Re: problem to solve - hotspot/object visibility
Post by: Matti on Fri 27/08/2010 13:10:08
Are you using an old version of AGS? If so, there's no global variables pane in the editor. You'd have to use Global ints or import/export variables you created in the global script. Otherwise just do what Khris said, he gave you an example.

Quote
my intention was to enable a hotspot only if there are all three items activated in my inventory, probably there is an other possibility to achieve the desired  result

So what's the problem, doesn't it work? As Khris said: Give us more info if you want to get help.

Title: Re: problem to solve - hotspot/object visibility
Post by: Fonda on Fri 27/08/2010 14:04:22
ok I did it  :=
unfortunately I wrote it in the globalscript.ASC firstly

THANX :)
Title: Re: problem to solve - hotspot/object visibility
Post by: Fonda on Fri 27/08/2010 14:32:23
the problem is that I want the hotspot to be enabled just if all three items are at the same time in my inventory



back to the first case:

function room_Load()
{
if (player.HasInventory(iSpiegel) || objectpick){

   oSpiegel.Visible=false;
}
...


this is an excerpt from my script, if I defined "bool objectpick=false;" in globalscript, does the function_room above asking, if objectpick equals false ?
Title: Re: problem to solve - hotspot/object visibility
Post by: amanta4ray on Fri 27/08/2010 15:24:57
I don't know if this is what you are looking for, but here goes....

In the room where you want the hotspot enabled go to where it says before room loads and add  

if (player.HasInventory(isomething)) &&  (player.HasInventory(isomething2)) && (player.HasInventory(isomething3)) {hotspot[2].Enabled=true;}
else {hotspot[2].Enabled=false;}

Just replace the inventory items to the ones you need and change the number of the hotspot to the one you are using.

The code above will tell the room that a certain hotspot will only be enabled if your player has all three items.

             Hope it helps
Title: Re: problem to solve - hotspot/object visibility
Post by: Fonda on Sat 28/08/2010 09:11:24
Quote from: amanta4ray on Fri 27/08/2010 15:24:57
I don't know if this is what you are looking for, but here goes....

In the room where you want the hotspot enabled go to where it says before room loads and add  

if (player.HasInventory(isomething)) &&  (player.HasInventory(isomething2)) && (player.HasInventory(isomething3)) {hotspot[2].Enabled=true;}
else {hotspot[2].Enabled=false;}

Just replace the inventory items to the ones you need and change the number of the hotspot to the one you are using.

The code above will tell the room that a certain hotspot will only be enabled if your player has all three items.

             Hope it helps

if I script it this way, the compiler rumbles at the &&'s, I'm using version 3.1.2
and if I define a bool or integer in globalscript, yes, I can use it in my rooms, but if I modify the values in room 1, there are no consequences in room 2. the values do not overreach the rooms.

Title: Re: problem to solve - hotspot/object visibility
Post by: tzachs on Sat 28/08/2010 10:57:42
That's because there's an extra ')' in there.
Do it like this:

if (player.HasInventory(isomething) && player.HasInventory(isomething2)
&& player.HasInventory(isomething3))
{
    hotspot[2].Enabled=true;
}
else
{
   hotspot[2].Enabled=false;
}
Title: Re: problem to solve - hotspot/object visibility
Post by: Khris on Sat 28/08/2010 12:50:24
Quote from: PeterFonda on Sat 28/08/2010 09:11:24
and if I define a bool or integer in globalscript, yes, I can use it in my rooms, but if I modify the values in room 1, there are no consequences in room 2. the values do not overreach the rooms.

Like I said, use the Global variables pane in the project tree.

You can define them in the script, too, but then you have to import them in the header. What you did is declare them in the header which will create one variable for each script, all with their own value.

// global.ash
import bool objectpick;    // import requires type, in this case "bool"


// global.asc
bool objectpick;
export objectpick;    // export requires name only, not type


amanta4ray's code won't work, the brackets are misplaced. tzachs' will.

If you get a compiler error, tell us the exact wording.
Title: Re: problem to solve - hotspot/object visibility
Post by: Fonda on Sat 28/08/2010 20:03:59
@Khris

ok, thanx