different reaction on stage entrance depending on inventory item

Started by P.Wilson, Sun 30/08/2015 13:05:03

Previous topic - Next topic

P.Wilson

Hello AGS community,

I`m pretty new to this paticulair program, i watched the "AGS making of sammys quest" several times, and read trough all kind of forums trying to help me out with this little problem.

I`m trying to make a game where you visite a certain area several times.
and depending on certain inventory items, how you enter this field and what it does.

I tried several different things, with the last one doing halve of what i want it to do,..

Code: ags
 function room_AfterFadeIn()]



Code: ags

 if ((player.InventoryQuantity[iSewerkey.ID] == 1))  
     Display("I now have a sewer key.");
  
  
else


  if ((player.InventoryQuantity[iSewerkey.ID] == 0) )
  Wait(20);
  cEgo.Walk(460, 400, eBlock);
  Display("I have to save Nik,...");
  Display("But i`d better prepair myself first.");
  Display("I have nothing usefull back at the house,...");
  Display("So i have to see what i can scounge up.");
}

]


the first time you enter you dont have the sewerkey, so you only do to block with "save nik" 
this works.

The second time you enter you do have the sewerkey, and you should skip the whole "save nik" and only do the  "i now have a sewer key"
but for some reason it follows up with the "save nik" block again

can someone tell me what i`m doing wrong?

thank you all in advanced.

Cassiebsg

That's a bit of a mess in there.

Let me see:

Code: ags

{
if ((player.HasInventory(iSewerkey))  // Are you planing on player having more than one Sewer key? And have difrent stuff hapening if so? Otherwise no need for quantity check. ;)
    Display("I now have a sewer key."); 
else
    { // Remember to open brackets if there's more than one line of commands.
    Wait(20);
    cEgo.Walk(460, 400, eBlock);
    Display("I have to save Nik,...");
    Display("But i`d better prepair myself first.");
    Display("I have nothing usefull back at the house,...");
    Display("So i have to see what i can scounge up.");
    } // And close them again once finished 
}


Hope it helps some what. :)
There are those who believe that life here began out there...

ChamberOfFear

Spoiler
[close]

Curly brackets is used to include several lines of code, you're code executes anyway because you don't have them. Without them the if and else-if will execute the first line after the condition only.

Code: ags

if(condition)
  DoSomething1(); // This will happen if condition1 is true
else if(condition2)
  DoSomething2(); // This will happen if condition2 is true
  DoSomething3(); // This will happen either way


You want do this
Code: ags

if(condition)
{
  DoSomething1(); // This will happen if condition1 is true
}
else if(condition2)
{
  DoSomething2(); // This will happen if condition2 is true
  DoSomething3(); // This will happen if condition2 is true
}
DoSomething4(); // This will happen either way


EDIT: I didn't notice you made two posts with the exact same question and got your answer already

Snarky

(Merged threads: Don't start multiple threads on the same question.)

P.Wilson

Thank you all for your quick resonces.

I`m sorry about the dubble post, my browser crashed while posting the first one, so i didnt think it got posted at all.

I`ll give your solutions a try and let you know the outcome

P.Wilson

 @Cassiebsg

your code worked perfectly,...  (almost)
you forgot 1 ) in the first line,..
but i was able to get everything to work thanks to your code.

So again, thanks a lot.

=====Edit
ok,..  i feel very stupid now.
some how, when i try to add extra commands after the  "now i have a sewerkey"  line,...
i suddenly get a error on the  ELSE  command :S


It should read like this:

Code: ags


function room_AfterFadeIn()


{
if ((player.HasInventory (iSewerkey)))  // Are you planing on player having more than one Sewer key? And have difrent stuff hapening if so? Otherwise no need for quantity check. ;)
    Door_002.Visible = true;
    oOpendoor.Visible = false;
    Wait(20);
    Display("I hope mr.Blue will find the key i left him on his table.");  //this is a housekey, not the sewerkey
    Display("and now I have a sewer key, i`m sure it will come in handy real soon");
 
  
    
    
else
    { // Remember to open brackets if there's more than one line of commands.
    Wait(20);
    cEgo.Walk(460, 400, eBlock);
    Display("I have to save Nik,...");
    Display("But i`d better prepair myself first.");
    Display("I have nothing usefull back at the house,...");
    Display("So i have to see what i can scounge up.");
    } // And close them again once finished 
}
 



SMF spam blocked by CleanTalk