Room Switching Problem*FIXED*

Started by Melee Island Resident, Mon 18/04/2011 22:47:10

Previous topic - Next topic

Melee Island Resident

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?

monkey0506

#1
You would do that by reading the tutorial. Or you know, learning anything about AGS.

Code: 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.

Khris

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.

monkey0506

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.

Melee Island Resident

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.

Code: 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

Melee Island Resident

Okay I have this:
Code: ags
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 "}"

ddq

Code: ags

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.

Khris

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

Code: ags
function hGate_Useinv() 
{

}


Now add to that:

Code: ags
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.");
}

Melee Island Resident

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

Code: ags
function hGate_Useinv() 
{

}


Now add to that:

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

ddq

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.

monkey0506

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)

Khris

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. :)

Melee Island Resident

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

Matti

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.

SMF spam blocked by CleanTalk