Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Melee Island Resident on Mon 18/04/2011 22:47:10

Title: Room Switching Problem*FIXED*
Post by: Melee Island Resident on Mon 18/04/2011 22:47:10
If i wanted to make it so that if i had an inventory item selected, i could click on a door and it would take me to the next room, how would i do that?
Title: Re: Room Switching Problem
Post by: monkey0506 on Mon 18/04/2011 22:58:52
You would do that by reading the tutorial. Or you know, learning anything about AGS.

// room script

function oDoor_Click()
{
 if (player.ActiveInventory == iKey)
 {
   // animate door opening and player walking through door
   player.ChangeRoom(2);
 }
}


I won't explain anything else about the code..where to put it..or how to customize it to your needs. Until you read the tutorial and post an example of what you've actually done for yourself. Not to be rude, just saying.
Title: Re: Room Switching Problem
Post by: Khris on Mon 18/04/2011 23:32:23
I didn't check it right now, but last time I checked, the use of player.ActiveInventory isn't explained anywhere in the tutorial. This is a glaring omission that was pointed out by me at least once already because this question keeps popping up.
On the other hand, there are bound to be many threads about this already, so using the forum search first (as required by the rules, afaik) would have been the way to go here.
Title: Re: Room Switching Problem
Post by: monkey0506 on Mon 18/04/2011 23:49:19
Between the editor tutorial and the scripting tutorial one could at least learn how to use AGS. This question is less about checking if a player used an inventory item on an object, and more about using the program.
Title: Re: Room Switching Problem
Post by: Melee Island Resident on Tue 19/04/2011 16:42:58
Quote from: monkey_05_06 on Mon 18/04/2011 22:58:52
You would do that by reading the tutorial. Or you know, learning anything about AGS.

// room script

function oDoor_Click()
{
 if (player.ActiveInventory == iKey)
 {
   // animate door opening and player walking through door
   player.ChangeRoom(2);
 }
}


I won't explain anything else about the code..where to put it..or how to customize it to your needs. Until you read the tutorial and post an example of what you've actually done for yourself. Not to be rude, just saying.
this didn't work
i'll take another look at the tutorials and see if i can find what im doing wrong
Title: Re: Room Switching Problem
Post by: Melee Island Resident on Tue 19/04/2011 17:15:29
Okay I have this:
function hGate_Interact(){
if (player.HasInventory(iKey))
{
player.ChangeRoom(2);
}


And it's giving me this error message:
Quoteroom1.asc(-10): Runtime error: Function still open, missing "}"
Title: Re: Room Switching Problem
Post by: ddq on Tue 19/04/2011 17:28:25

function hGate_Interact()
{
    if ( player.HasInventory(iKey) )
    {
        player.ChangeRoom(2);
    }
}


You were missing a "}", just like it said. Indentation helps in matching up your braces.
Title: Re: Room Switching Problem
Post by: Khris on Tue 19/04/2011 18:02:06
Also, this isn't really the way to do what you want. (Unless you want to keep the interface really simple.)

What you need is the "use inventory with hotspot" event. This will create

function hGate_Useinv()
{

}


Now add to that:

function hGate_Useinv()
{
  if (player.ActiveInventory == iKey) {
    Display("You unlock the gate and proceed down the alley.");
    player.ChangeRoom(2);
  }
  else player.Say("That doesn't make sense. I need to use a key.");
}
Title: Re: Room Switching Problem
Post by: Melee Island Resident on Tue 19/04/2011 18:07:27
Quote from: Khris on Tue 19/04/2011 18:02:06
Also, this isn't really the way to do what you want. (Unless you want to keep the interface really simple.)

What you need is the "use inventory with hotspot" event. This will create

function hGate_Useinv()
{

}


Now add to that:

function hGate_Useinv()
{
  if (player.ActiveInventory == iKey) {
    Display("You unlock the gate and proceed down the alley.");
    player.ChangeRoom(2);
  }
  else player.Say("That doesn't make sense. I need to use a key.");
}

you rule dude
Title: Re: Room Switching Problem
Post by: ddq on Tue 19/04/2011 18:09:18
While "classic", the old "use key on door" "puzzle" is more than a bit "stupid" ("quotation marks"). If you are set on requiring the player to click on the key and then click on the door, then you need Khris' method, but in this instance, it is reasonable to open the door for the player as long as they have the key in their inventory. This is just an issue of game design, but regardless, you should know how to actually deal with "use inventory with hotspot" interactions, which Khris has explained.
Title: Re: Room Switching Problem*FIXED*
Post by: monkey0506 on Tue 19/04/2011 21:16:46
What's awesome is how that's essentially the exact same code that I provided, with the exception that Khris actually had some information about what was expected..oh, and of course, my near-identical code didn't work! (Because of user-error, not because of invalid code)
Title: Re: Room Switching Problem*FIXED*
Post by: Khris on Tue 19/04/2011 21:50:50
MIR stated in the very first post what he was trying to do. And it was something that isn't explained anywhere in the tutorial or even the manual.
He certainly did look at the tutorial or a similar resource, because otherwise his first question had been about something that is actually answered there. Which can't be said for many other newbies, btw.

Quote from: monkey_05_06 on Mon 18/04/2011 23:49:19This question is less about checking if a player used an inventory item on an object, and more about using the program.
My impression from the very beginning was, no, not at all, it is precisely about Useinv/player.ActiveInventory. And it turned out to be.

Your post was at the time not very helpful, with _Click in the code and no further explanation.
I'm really wondering why with all the n00bs here you're bashing the newbie. He even edited the topic to say *FIXED* without people telling him to.
He does senselessly quote the complete previous post, putting a one-line below it though. :)
Title: Re: Room Switching Problem*FIXED*
Post by: Melee Island Resident on Tue 19/04/2011 22:25:52
Quote from: Khris on Tue 19/04/2011 21:50:50He even edited the topic to say *FIXED* without people telling him to.
He does senselessly quote the complete previous post, putting a one-line below it though. :)
well i just saw other people put *FIXED* in the title so i thought it was what you were probably supposed to do

also on my other two forums people will usually quote entirely what the other person said so sorry about that
Title: Re: Room Switching Problem*FIXED*
Post by: Matti on Wed 20/04/2011 11:18:36
Quote from: Melee Island Resident on Tue 19/04/2011 22:25:52
well i just saw other people put *FIXED* in the title so i thought it was what you were probably supposed to do

That's exactly what you're supposed  to do.  ;)

Quote
also on my other two forums people will usually quote entirely what the other person said so sorry about that

Quoting a whole post, especially one that is right above your post, doesn't make any sense and makes the thread unnecessarily long and hard to read. So we're not too happy with people doing that.