Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Ico on Thu 30/09/2010 18:21:50

Title: How do I give object to character conditionally?
Post by: Ico on Thu 30/09/2010 18:21:50
I've searched the forums and tutorials and I'm still having a hard time figuring this out. I already know how to put objects in the inventory and give objects away. But say I want to give objectB to character2 only on the condition that I gave objectA to character1 first, not allowing me to give objectB to character2 if I didn't give objectA to character1. How would I script that? Thanks.
Title: Re: How do I give object to character conditionally?
Post by: Ryan Timothy B on Thu 30/09/2010 18:34:30
There are two ways you could do this.

1: With a global variable boolean (the most desired option).
When you hand ObjectA to Character1, you set the boolean as true. Then check if it's true before allowing you to hand ObjectB to Character2.

OR

2: Give the inventory ObjectA to Character1. (I've never even tried this method, but I imagine there are zero issues with it)
First by removing it from your inventory and then adding it to Character1's inventory: cCharacter1.AddInventory(iObjectA);
And checking if Character1 has the ObjectA before allowing you to hand ObjectB to Character2: cCharacter1.HasInventory(iObjectA)
Title: Re: How do I give object to character conditionally?
Post by: Ico on Thu 30/09/2010 19:33:32
I still can't figure out how to get the bool way to work. I tried the second way you listed and it worked, but I'm having trouble figuring out how to make the object invisible once I get it off the shelf. I'm typing in ObjectB.Visible = false; but it's calling it an undefined token for some reason.
Title: Re: How do I give object to character conditionally?
Post by: Ryan Timothy B on Thu 30/09/2010 19:42:55
You must use the exact spelling for the name of the object that you named in the room editor.

Or you could simply use the index way. Example: object[x].Visible = false;  (with x being the number of the room object)
But you'd need to know the number for that object, and it's much less readable.

Edit: no idea how the bullet came about. :P
Title: Re: How do I give object to character conditionally?
Post by: Calin Leafshade on Thu 30/09/2010 19:56:20
Title: Re: How do I give object to character conditionally?
Post by: Ico on Thu 30/09/2010 20:41:48
Oh thanks, I got the image visibility false now. Now if only I can figure out the bool way for when I need my character to retrieve an item from a specific spot rather than from another character.
Title: Re: How do I give object to character conditionally?
Post by: Khris on Thu 30/09/2010 21:18:14
Use the Global variables pane in the editor tree to create a boolean variable.
Now you can set this variable to true as soon as the player did something; in the code for the other event all you do is compare the variable to true and act accordingly.
Title: Re: How do I give object to character conditionally?
Post by: Ico on Thu 30/09/2010 22:15:15
Ah, I got it now! I feel stupid, thanks everyone, AGS community is awesome helpful.