script wont set dialog option on - SOLVED

Started by Gepard, Tue 20/04/2010 07:24:05

Previous topic - Next topic

Gepard

 
Code: ags
if (IsKeyPressed(83)==1) {
   if (GetGlobalInt(24)==0) {
   character[O].Walk (171, 104, eBlock, eAnywhere);
   if (GetGlobalInt(30)==2) if (player.InventoryQuantity[44]>=1) dOleg.SetOptionState (11, eOptionOn);
   else if (GetGlobalInt(30)==3) if (player.InventoryQuantity[45]>=1) dOleg.SetOptionState (11, eOptionOn);
   else if (GetGlobalInt(30)==4) if (player.InventoryQuantity[46]>=1) dOleg.SetOptionState (11, eOptionOn);
   else if (GetGlobalInt(30)==5) if (player.InventoryQuantity[47]>=1) dOleg.SetOptionState (11, eOptionOn);
   else if (GetGlobalInt(30)==6) if (player.InventoryQuantity[48]>=1) dOleg.SetOptionState (11, eOptionOn);
   else if (GetGlobalInt(30)==7) if (player.InventoryQuantity[49]>=1) dOleg.SetOptionState (11, eOptionOn);
   else if (GetGlobalInt(30)==8) if (player.InventoryQuantity[51]>=1) dOleg.SetOptionState (11, eOptionOn);
   dOleg.Start ();
   SetGlobalInt (24, 1);
   }
   }


This is the script for while player is standing on region... The option wont show in the dialog. I have no idea why. There is no option-off-forever in my script, globalint was set to number 8 previously and my character has the item 51 so I really dont know what is going on here.
Drink up me 'arties! Yo ho!

Khris

Code: ags
   if (GetGlobalInt(30)==2) if (player.InventoryQuantity[44]>=1) dOleg.SetOptionState (11, eOptionOn);
   else if (GetGlobalInt(30)==3) if (player.InventoryQuantity[45]>=1) dOleg.SetOptionState (11, eOptionOn);
   else if (GetGlobalInt(30)==4) if (player.InventoryQuantity[46]>=1) dOleg.SetOptionState (11, eOptionOn);
   else if (GetGlobalInt(30)==5) if (player.InventoryQuantity[47]>=1) dOleg.SetOptionState (11, eOptionOn);
   else if (GetGlobalInt(30)==6) if (player.InventoryQuantity[48]>=1) dOleg.SetOptionState (11, eOptionOn);
   else if (GetGlobalInt(30)==7) if (player.InventoryQuantity[49]>=1) dOleg.SetOptionState (11, eOptionOn);
   else if (GetGlobalInt(30)==8) if (player.InventoryQuantity[51]>=1) dOleg.SetOptionState (11, eOptionOn);

is basically equivalent to:
Code: ags
  if (GetGlobalInt(30) > 1 && player.InventoryQuantity[GetGlobalInt(30)+42] > 0) dOleg.SetOptionState (11, eOptionOn);

except for the very last line where it says 51 instead of 50. Maybe that's causing the problem?

Anyway, you'll do yourself a huge favor if you start cleaning up your code. The sooner you do this, the faster will you stop looking hours for easy to miss typos in unnecessarily huge scripts.

Also, if character[0] is the player, why do you use the former in one line, then the latter in another?
And why are you still using ugly, obsolete GlobalInts?

Also, it's erasier for us to help you if we know what a piece of code is supposed to do, in terms of game design.

Gepard

1. No, it is 51, not 50.
2. I do not know how to clean the code. I do my best really.
3. Character O is NPC named Oleg, its not the player.
4. The Globalint 30 set to different value represents different missions. For each of the missions you need to get specific item and when you have it, you can than talk about it to the "O" character using the option 11 (different reaction is than determined in dialog request function).
Drink up me 'arties! Yo ho!

Dualnames

Code: ags

if ((IsKeyPressed(83)==1) && (GetGlobalInt(24)==0)) {
    character[O].Walk (171, 104, eBlock, eAnywhere);
    int checking=43;
    int twoeight=1;
while (checking!=51) {
           checking++;
           twoeight++;
          if (checking==50) checking++;
          if ((GetGlobalInt(30)==twoeight) && (player.InventoryQuantity[checking]>=1))        dOleg.SetOptionState (11, eOptionOn);
}
}


Here's another alternative. This should definitely trigger the option to be turned on.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Gepard

No it did not :( but if I put the dOleg.SetOptionState (11, eOptionOn); as a simple command without if getglobalint... it will show up so it must be something... I dont know. And why is it such a problem for AGS anyway to turn the option on? It looks like a simple script to me.
Drink up me 'arties! Yo ho!

Khris

It just realized what I think is screwing things up.

In theory, it is possible to use this:
  if (a) if (b) c();
This is equivalent to
  if (a && b) c();
However, as soon as you continue using else [if], things will get out of order.

I tested it using this:
    if (true) if (false) Display("Heh.");
    else Display("Bork.");
As expected, I was greeted by "Bork." because the else is called due to the second condition being false.

A simple way of fixing this should be the removal of every else; they aren't needed here anyway since GlobalInts obviously can't have more than one distinct value.

Gepard

You are a genius! Works fine :) Thanks a million!
Drink up me 'arties! Yo ho!

SMF spam blocked by CleanTalk