Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Mkt2015 on Sun 12/12/2004 07:00:08

Title: Long if else statement help
Post by: Mkt2015 on Sun 12/12/2004 07:00:08
Excuse me for the length of this. I can get the first part to work. The part that has Speed, Evade, Hit and Weapon. It is still the rough draft...there are quite a few things I still have to put in in order for it to be a working "upgrade system", but I can't seem to get the other if and if else statements to work. It won't display the weapons or specials or skills. I have this under Global Script in the repeatedly execute part.

if ((IsKeyPressed(85)==1) && (IsKeyPressed(81)==0))
{
  DisplayAt(100, 100, 200, "(a)ttributes          (w)eapons          (s)pecial          s(k)ills          ");
  if ((IsKeyPressed(65)==1) && (IsKeyPressed(87)==0) && (IsKeyPressed(83)==0) & (IsKeyPressed(75)==0))
  {
    DisplayAt(100, 100, 200, "(s)peed          (e)vade          (h)it          (w)eapon          ");
    if ((IsKeyPressed(83)==1) && (IsKeyPressed(69)==0) && (IsKeyPressed(72)==0) && (IsKeyPressed(87)==0))
    {
      DisplayAt(100, 100, 200, "60, 70, 80, 90, 100");
    }
    else if ((IsKeyPressed(83)==0) && (IsKeyPressed(69)==1) && (IsKeyPressed(72)==0) && (IsKeyPressed(87)==0))
    {
      DisplayAt(100, 100, 200, "60, 70, 80, 90, 100");
    }
    else if ((IsKeyPressed(83)==0) && (IsKeyPressed(69)==0) && (IsKeyPressed(72)==1) && (IsKeyPressed(87)==0))
    {
      DisplayAt(100, 100, 200, "60, 70, 80, 90, 100");
    }
    else if ((IsKeyPressed(83)==0) && (IsKeyPressed(69)==0) && (IsKeyPressed(72)==0) && (IsKeyPressed(87)==1))
    {
      DisplayAt(100, 100, 200, "60, 70, 80, 90, 100");
    }
  }
  else if ((IsKeyPressed(65)==0) && (IsKeyPressed(87)==1) && (IsKeyPressed(83)==0) && (IsKeyPressed(75)==0))
  {
    DisplayAt(100, 300, 200, "a(x)e          sh(o)tgun          supe(r) shotgun          (n)ailgun          super nail(g)un          grena(d)e launcher          ro(c)ket launcher          (t)hunderbolt          ");
    if ((IsKeyPressed(88)==1) && (IsKeyPressed(79)==0) && (IsKeyPressed(82)==0) && (IsKeyPressed(78)==0) && (IsKeyPressed(71)==0) && (IsKeyPressed(68)==0) && (IsKeyPressed(67)==0) && (IsKeyPressed(84)==0))
    {
      DisplayAt(100, 300, 200, "(1)Multiple Targets/2          (2)Multiple Targets/3          (3)Double Shot          (4)Triple Shot          ");
    }
    else if ((IsKeyPressed(88)==0) && (IsKeyPressed(79)==1) && (IsKeyPressed(82)==0) && (IsKeyPressed(78)==0) && (IsKeyPressed(71)==0) && (IsKeyPressed(68)==0) && (IsKeyPressed(67)==0) && (IsKeyPressed(84)==0))
    {
      DisplayAt(100, 300, 200, "(1)Multiple Targets/2          (2)Multiple Targets/3          (3)Double Shot          (4)Triple Shot          ");
    }
    else if ((IsKeyPressed(88)==0) && (IsKeyPressed(79)==0) && (IsKeyPressed(82)==1) && (IsKeyPressed(78)==0) && (IsKeyPressed(71)==0) && (IsKeyPressed(68)==0) && (IsKeyPressed(67)==0) && (IsKeyPressed(84)==0))
    {
      DisplayAt(100, 300, 200, "(1)Multiple Targets/2          (2)Multiple Targets/3          (3)Double Shot          (4)Triple Shot          ");
    }
    else if ((IsKeyPressed(88)==0) && (IsKeyPressed(79)==0) && (IsKeyPressed(82)==0) && (IsKeyPressed(78)==1) && (IsKeyPressed(71)==0) && (IsKeyPressed(68)==0) && (IsKeyPressed(67)==0) && (IsKeyPressed(84)==0))
    {
      DisplayAt(100, 300, 200, "(1)Multiple Targets/2          (2)Multiple Targets/3          (3)Double Shot          (4)Triple Shot          ");
    }
    else if ((IsKeyPressed(88)==0) && (IsKeyPressed(79)==0) && (IsKeyPressed(82)==0) && (IsKeyPressed(78)==0) && (IsKeyPressed(71)==1) && (IsKeyPressed(68)==0) && (IsKeyPressed(67)==0) && (IsKeyPressed(84)==0))
    {
      DisplayAt(100, 300, 200, "(1)Multiple Targets/2          (2)Multiple Targets/3          (3)Double Shot          (4)Triple Shot          ");
    }
    else if ((IsKeyPressed(88)==0) && (IsKeyPressed(79)==0) && (IsKeyPressed(82)==0) && (IsKeyPressed(78)==0) && (IsKeyPressed(71)==0) && (IsKeyPressed(68)==1) && (IsKeyPressed(67)==0) && (IsKeyPressed(84)==0))
    {
      DisplayAt(100, 300, 200, "(1)Multiple Targets/2          (2)Multiple Targets/3          (3)Double Shot          (4)Triple Shot          ");
    }
    else if ((IsKeyPressed(88)==0) && (IsKeyPressed(79)==0) && (IsKeyPressed(82)==0) && (IsKeyPressed(78)==0) && (IsKeyPressed(71)==0) && (IsKeyPressed(68)==0) && (IsKeyPressed(67)==1) && (IsKeyPressed(84)==0))
    {
      DisplayAt(100, 300, 200, "(1)Multiple Targets/2          (2)Multiple Targets/3          (3)Double Shot          (4)Triple Shot          ");
    }
    else if ((IsKeyPressed(88)==0) && (IsKeyPressed(79)==0) && (IsKeyPressed(82)==0) && (IsKeyPressed(78)==0) && (IsKeyPressed(71)==0) && (IsKeyPressed(68)==0) && (IsKeyPressed(67)==0) && (IsKeyPressed(84)==1))
    {
      DisplayAt(100, 300, 200, "(1)Multiple Targets/2          (2)Multiple Targets/3          (3)Double Shot          (4)Triple Shot          ");
    }
  }
  else if ((IsKeyPressed(65)==0) && (IsKeyPressed(87)==0) && (IsKeyPressed(83)==1) && (IsKeyPressed(75)==0))
  {
    DisplayAt(100, 300, 200, "(1)Environment          (2)Experience          (3)Luck          ");
    if ((IsKeyPressed(49)==1) && (IsKeyPressed(50)==0) && (IsKeyPressed(51)==0))
    {
      DisplayAt(100, 300, 200, "60%, 70%, 80%, 90%, 100%");
    }
    else if ((IsKeyPressed(49)==0) && (IsKeyPressed(50)==1) && (IsKeyPressed(51)==0))
    {
      DisplayAt(100, 300, 200, "+15, +15, +25, +35, +55");
    }
    else if ((IsKeyPressed(49)==0) && (IsKeyPressed(50)==0) && (IsKeyPressed(51)==1))
    {
      DisplayAt(100, 300, 200, "20%, 40%, 60%, 80%, 100%");
    }
  }
  else if ((IsKeyPressed(65)==0) && (IsKeyPressed(87)==0) && (IsKeyPressed(83)==0) && (IsKeyPressed(75)==1))
  {
    DisplayAt(100, 300, 200, "(1)Rocket-Jump          (2)Long-Jump          (3)High-Jump          ");
    if ((IsKeyPressed(49)==1) && (IsKeyPressed(50)==0) && (IsKeyPressed(51)==0))
    {
      DisplayAt(100, 300, 200, "60%, 70%, 80%, 90%, 100%");
    }
    else if ((IsKeyPressed(49)==0) && (IsKeyPressed(50)==1) && (IsKeyPressed(51)==0))
    {
      DisplayAt(100, 300, 200, "60%, 70%, 80%, 90%, 100%");
    }
    else if ((IsKeyPressed(49)==0) && (IsKeyPressed(50)==0) && (IsKeyPressed(51)==1))
    {
      DisplayAt(100, 300, 200, "60%, 70%, 80%, 90%, 100%");
    }
  }
}
Title: Re: Long if else statement help
Post by: Radiant on Sun 12/12/2004 07:34:03
I don't think that's quite how IsKeyPressed() works. You put up a dialog box (with display()), which is cleared by a mouseclick or pressing enter or something. Then you check which key, at that moment, is pressed. Assumedly it would work if you held down, say, 'A', then pressed the mouse button to close the dialog, but that's probably not what you want.

Suggestion: use GUIs rather than text boxes, and use the on_key_press() global script function (combined with if (IsGUIOn ())) to find out which menu is up.
Or, use the dialog system (which responds to the 1-9 keys).
Title: Re: Long if else statement help
Post by: RickJ on Sun 12/12/2004 17:55:46
In addition only one key can be pressed at a time so instead of the convuluted logic you have you only need something like

if (IsKeyPressed(69)==1){
}
else if  (IsKeyPressed(70)==1){
}
(IsKeyPressed(71)==1){
}
      :
(IsKeyPressed(72)==1){
}

Also this line has an error in that you said "&" when I think you meant tosay "&&"
Quote
if ((IsKeyPressed(65)==1) && (IsKeyPressed(87)==0) && (IsKeyPressed(83)==0) & (IsKeyPressed(75)==0))
Title: Re: Long if else statement help
Post by: Mkt2015 on Wed 15/12/2004 19:39:26
Actually, Rick, I had about eight lines of code and the only way they would work was if I used that convoluted logic. I'm still figuring out the intricacies of AGS, but so far I'm doing all right.
Title: Re: Long if else statement help
Post by: on Wed 15/12/2004 20:17:09
Don't know if this makes any sense - it depends on your chosen resolution - but I noticed your y-coordinates was changed to 300 from the point where they weren't displayed (as opposed to 100 above it).