Script RPG damage (SOLVED)

Started by ncw14, Wed 09/01/2008 23:43:58

Previous topic - Next topic

ncw14

Okay another of my 1000 problems on making my rpg heres the script for button 1 on interface Gui2

//More Script above and below but not concerning this problem

if (button ==1) {   
if (GetGlobalInt(4) >= 2) {
Display("You Caused 10 To 13 Damage.");
SetGlobalInt(5, GetGlobalInt(5)-10 - Random(3));}
if (GetGlobalInt(5) <= 0) {
GUIOff(GUI2);
player.ChangeRoom(1, 205, 230);
SetCursorMode(0);
Display("You Defeated The Enemy.");
Wait(30);
GUIOn(STATUSLINE);
SetGlobalInt(3, GetGlobalInt(3)+20);
SetGlobalInt(2, GetGlobalInt(2)+20);
SetGlobalInt(5, 50);}
else {
if (GetGlobalInt(4) <=1) {
  Display("You Are Not High Enough Level");}}
if (GetGlobalInt(4) >=2) {
if (GetGlobalInt(5) >=1) {
GiveScore(-11);
Display ("The Enemy Did 11 damage");}}}}

my problem - my health is the score. but after i leave the room Globalint 2 is set to 50 again so i can rebattle him. but since  it is not 0 or lower i get hurt 11 how do i fix this

monkey0506

My first concern was your indentation (rather the lack thereof) which makes the script very hard to follow. The next thing I noticed was that you're using some outdated coding styles. You are however using the player pointer keyword (as in player.ChangeRoom(...)) so I know you're using at least AGS 2.7. So the code should really be updated

Code: ags
//More Script above and below but not concerning this problem

if (button ==1) {
  if (GetGlobalInt(4) >= 2) {
    Display("You Caused 10 To 13 Damage."); 
    SetGlobalInt(5, GetGlobalInt(5) - 10 - Random(3));
  }
  else if (GetGlobalInt(5) <= 0) {
    gGui2.Visible = false;
    player.ChangeRoom(1, 205, 230);
    mouse.Mode = eModeWalkto;
    Display("You Defeated The Enemy.");
    Wait(30);
    gStatusline.Visible = true;
    SetGlobalInt(3, GetGlobalInt(3) + 20);
    SetGlobalInt(2, GetGlobalInt(2) + 20);
    SetGlobalInt(5, 50);
  }
  else if (GetGlobalInt(4) <=1) Display("You Are Not High Enough Level");
  else if (GetGlobalInt(4) >=2) {
    if (GetGlobalInt(5) >=1) {
      GiveScore(-11);
      Display ("The Enemy Did 11 damage");
    }
  }
}


I'm unsure what your global ints are being used for, so I'm not entirely clear which variables are being set wrong or require an extra check. But shouldn't this code only be getting run if you click on button 1 of Gui2? In this case I don't see why you would instantaneously be getting hurt. Perhaps I'm misunderstanding something here.

Oh, and also, it wouldn't hurt for you to update to using 2.7+ style event handlers. You should assign button 1 a script o-name and then you can double click the control to open it's specialized event handler instead of using the deprecated interface_click.

BTW, you can use the [code][/code] tags to enclose code like I've done above.

SMF spam blocked by CleanTalk