How do I give object to character conditionally?

Started by Ico, Thu 30/09/2010 18:21:50

Previous topic - Next topic

Ico

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.

Ryan Timothy B

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:
Code: ags
cCharacter1.AddInventory(iObjectA);

And checking if Character1 has the ObjectA before allowing you to hand ObjectB to Character2:
Code: ags
cCharacter1.HasInventory(iObjectA)

Ico

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.

Ryan Timothy B

#3
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:
Code: ags
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

Calin Leafshade

#4
  • bullets
  • are
  • cool


    on topic, you can't reference an object name from a global script. You can only do that from a room script.

    you need to refer to the object by index like this

    Code: ags
    
    
    object[i].Visible = false;
    
    


Ico

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.

Khris

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.

Ico

Ah, I got it now! I feel stupid, thanks everyone, AGS community is awesome helpful.

SMF spam blocked by CleanTalk