If else-- solved

Started by dbuske, Tue 31/07/2012 13:00:26

Previous topic - Next topic

dbuske




if(cMarvin.ActiveInventory==iBook) {
    Display(".");
}
    else {
        Display(".");
    }
}

The above does not work.  Each character has an inventory item he recieves to calm down. A wrong item gets a different response.
They should give the else response. They always respond with the if response.
What if your blessings come through raindrops
What if your healing comes through tears...

Crimson Wizard

But you have SAME command both under "if" and under "else"...

dbuske

Quote from: Crimson Wizard on Tue 31/07/2012 13:11:32
But you have SAME command both under "if" and under "else"...
???
What if your blessings come through raindrops
What if your healing comes through tears...

Crimson Wizard

Here's the code you posted:
Code: ags

if(cMarvin.ActiveInventory==iBook) {
    Display(".");
}
    else {
        Display(".");
    }

This means:
IF Marvin's active inventory is Book, then Display(".");
ELSE Display(".");

It will do Display(".") always.
Is this really what you have in your code, or you just removed the actual text?

dbuske

#4
Yes I removed the text.  The else response is a negative statement that tells the player they gave the wrong item.
Preceding this I made the iBook the activeinventory item.
What if your blessings come through raindrops
What if your healing comes through tears...

Crimson Wizard

#5
I do not see how this can work wrong from the code you posted.

Maybe you can show all the code from this function? By the way, what function is this - "use inventory on character" event handler?

EDIT: Also, is cMarvin a player character?

dbuske

#6
function cMarvin_UseInv()
{
cMarvin.AddInventory(iBook);
cMarvin.ActiveInventory = (iBook);
cNano.LoseInventory(iBook);
  if(cMarvin.ActiveInventory==iBook)
      {
      Display("Finally, someone who appreciates how truly awful life really is.  I think I'll shut myself down now, or stick my head in a bucket of water for a while.");
      }
        else
    { 
      Display("That's even more depressing.");
    }
}

This is in the global script.
Good point about the Use inventory on character function.  I will check that out. I just used Useinv.
What if your blessings come through raindrops
What if your healing comes through tears...

Crimson Wizard

#7
Well, it is all clear now.
Look at your code. What do you do?
1. Set Marvin's active inventory to iBook.
2. Check if Marvin's active inventory is iBook.
Ofcourse it will always be iBook, and it will always display the text under "if", and never under "else".

Try this instead:
Code: ags

function cMarvin_UseInv()
{
  if(cNano.ActiveInventory==iBook)
  {
    Display("Finally, someone who appreciates how truly awful life really is.  I think I'll shut myself down now, or stick my head in a bucket of water for a while.");
    cMarvin.AddInventory(iBook);
    cNano.LoseInventory(iBook); 
  }
  else 
  {  
    Display("That's even more depressing.");
  }
}


Quote from: dbuske
Good point about the Use inventory on character function.  I will check that out. I just used Useinv.
Well, that seems to be exactly the same.

dbuske

Thank You, I will try it out right now.
What if your blessings come through raindrops
What if your healing comes through tears...

NickyNyce

you were attempting to have the character without the book USE the book on himself. Crimson Wizard should have made things right for you now.

You don't need the ...cMartin.ActiveInventory=(iBook);

From the looks of it, you were doing this so that your code would work, and the only reason it kind of did was because you were setting cMartins ActiveInventory to the book before the IF statement. It should be Nano giving the book to cMartin like Crimson Wizard drew up for you. Also the reason why it kind of worked was because you gave cMartin the Book before the IF statement ran.


dbuske

Thanks, I will work on it again today.
What if your blessings come through raindrops
What if your healing comes through tears...

dbuske

The code for Nano giving the inv item is in the room script.
What if your blessings come through raindrops
What if your healing comes through tears...

Crimson Wizard

Quote from: dbuske on Wed 01/08/2012 18:49:50
The code for Nano giving the inv item is in the room script.
Do you mean you just wrote a function with "Useinv" postfix without actually binding it to event? That's not correct then.
Also, it really depends on what actually Marvin is. If it is a room object or hotspot, then event function should stay in the room. If it is a character, it must be put into GlobalScript.

dbuske

Quote from: Crimson Wizard on Wed 01/08/2012 19:41:51
Quote from: dbuske on Wed 01/08/2012 18:49:50
The code for Nano giving the inv item is in the room script.
Do you mean you just wrote a function with "Useinv" postfix without actually binding it to event? That's not correct then.
Also, it really depends on what actually Marvin is. If it is a room object or hotspot, then event function should stay in the room. If it is a character, it must be put into GlobalScript.
ing  room script
Nano is the main character. So, I should put Nano's giving the inv item with the if else in the global script?  The giving the item is scripted as an event in the room script.
What if your blessings come through raindrops
What if your healing comes through tears...

NickyNyce

#14
Like Crimson Wizard said, all this should be in cMartins UseInv function. Which will be located in the global script when you make the function.

if(cNano.ActiveInventory==iBook)
  {
     Display("Finally, someone who appreciates how truly awful life really is.  I think I'll shut myself down now, or stick my head in a bucket of water for a while.");
     cMarvin.AddInventory(iBook);
     cNano.LoseInventory(iBook);
  }
  else
  { 
     Display("That's even more depressing.");
  }   
}

Crimson Wizard

Quote from: dbuske on Wed 01/08/2012 21:21:35
Nano is the main character. So, I should put Nano's giving the inv item with the if else in the global script?  The giving the item is scripted as an event in the room script.
I think you are missing the point a little. The question is not about Nano, but about the one to WHOM it gives an item.
To put it simply: it depends on what object does player interact with.

When player interacts with Characters (for example: gives inventory) and Inventory Items (for example: looks at them), the event should be scripted in the GlobalScript.
When player interacts with room Objects and Hotspots, the event should be scripted in the Room script.

So, yes, you should put the event with giving an item to the GlobalScript.

Also - that's very important! - do not forget to actually bind your function with event. Simply naming it with "Useinv" won't work.
You should set the name of your function for "Use inventory on character" event in character properties. Not player character (Nano), but NPC character (Marvin).

SMF spam blocked by CleanTalk