if( cEgo.Room == 55)

Started by cjhrules, Wed 20/09/2006 01:05:23

Previous topic - Next topic

cjhrules

I have this really strange problem:

I use the statement if( cEgo.Room == 55)  in  a function in the global script like this:
Code: ags

function InitSides ()
{
if( cEgo.Room == 55) 
{ 
sides [0].fight_view = 156;
sides [1].fight_view = 156; 
}
else 
{ 
sides [0].fight_view = 22;  
sides [1].fight_view = 53;
}
}

The prolem is if I start in room 55 and then it works. But if I start in say room number 54 and then walk into room 55 using NewRoom (EGO,...etc) the function won't  detect the room change to 55. why?

Btw! this works with every other function I have... so why not this one?

monkey0506

Where do you call InitSides from? Presumably it's not being called. I find that Display is very useful for debugging as well. You can try and use that to figure out what's going on (i.e., if cEgo.Room isn't 55, you could find out what it IS).

cjhrules

#2
well the strange thing is that I am runing other functions at the same time that works with the exact same condition... bizzare! :( I get the feeling that this function is only checking the room in the start of the game and after that it never updates so to speak. What have i missed? It's a part of a bigger function in the global script btw...

monkey0506

But still...where in your scripts do you call it from?

GarageGothic

As monkey asked, where do you call the function from? It would make most sense to use the EnterRoomBeforeFadein event. Make sure you're not calling it in First Time Player Enters Room interaction, which would explain why it only ran once.

What you want is something like:
Code: ags
function on_even(EventType event, int data) {
   if (event == eEventEnterRoomBeforeFadein) {
      Initsides();
   }
}

cjhrules

the main function is called after certain events taking place in the room. So the function is called after walking onto a region in the room 55.

monkey0506

Is there some reason you can't post a code snippet? It's difficult for us to say what's happening if you won't let us look at it.

cjhrules

I can post the whole fight script but it is very long... do you have time? Here it is
As you see I use the condition on 3 dif places and it works on the last place
I found this code on a AGS site but I have modified quite a bit since then.

Code: ags

int testar;

#define BOX_GUI_Y 150

#define HIT_ABOVE 5
#define HIT_MIDDLE 2
#define HIT_DOWN 1

int box_side = 0;

struct sside
{
  int fight_view;
  int button9, button6, button3, button7, button4, button1;
  };
  
sside sides [2];

int gb_duration = -1;
int gb_action = 0;

int g_opponent = -1;
int g_fightview = 0;
int g_inertia = 0;
int g_duration = 0;
int g_action = 0;

struct sbeam
{
  int x, y, width, height;
  int max, value;
  int max_color, value_color;
  };
  
sbeam beam_info [4];

function InitSides ()
{
if( cEgo.Room == 55) 
{ 
sides [0].fight_view = 156;
  sides [0].button9 = 1;
  sides [0].button6 = 2;
  sides [0].button3 = 3;
  sides [0].button7 = 4;
  sides [0].button4 = 5; 
  sides [0].button1 = 6;
  sides [1].fight_view = 156;
  sides [1].button9 = 4;
  sides [1].button6 = 5;
  sides [1].button3 = 6;
  sides [1].button7 = 1;
  sides [1].button4 = 2; 
  sides [1].button1 = 3;
}

else 
{ 
sides [0].fight_view = 22;
  sides [0].button9 = 1;
  sides [0].button6 = 2;
  sides [0].button3 = 3;
  sides [0].button7 = 4;
  sides [0].button4 = 5; 
  sides [0].button1 = 6;
  sides [1].fight_view = 53;
  sides [1].button9 = 4;
  sides [1].button6 = 5;
  sides [1].button3 = 6;
  sides [1].button7 = 1;
  sides [1].button4 = 2; 
  sides [1].button1 = 3;
}
}


  function BeamSettings ()
  {
    
    if( cEgo.Room == 55) 
    {
    int start_y = BOX_GUI_Y;
    beam_info [0].x =327;
    beam_info [0].y = start_y + 5;
    beam_info [0].width = 52;
    beam_info [0].height = 5;
    beam_info [0].max = 15;
    beam_info [0].value = 3;
    beam_info [0].max_color = 1;
    beam_info [0].value_color = 9;
    // Player - Helth
    beam_info [1].x = 327;
    beam_info [1].y = start_y + 15;
    beam_info [1].width = 166;
    beam_info [1].height = 5;
    beam_info [1].max = 100;
    beam_info [1].value = 3;
    beam_info [1].max_color = 16;
    beam_info [1].value_color = 14;
    // Opponent - Punch
    start_y += 25;
    beam_info [2].x = 327;
    beam_info [2].y = start_y + 5;
    beam_info [2].width = 52;
    beam_info [2].height = 5;
    beam_info [2].max = 15;
    beam_info [2].value = 3;
    beam_info [2].max_color = 1;
    beam_info [2].value_color = 9;
    // Opponen - Helth
    beam_info [3].x = 327;
    beam_info [3].y = start_y + 15;
    beam_info [3].width = 166;
    beam_info [3].height = 5;
    beam_info [3].max = 100;
    beam_info [3].value = 3;
    beam_info [3].max_color = 16;
    beam_info [3].value_color = 2;
}
else     {
  int start_y = BOX_GUI_Y;
    beam_info [0].x =126;
    beam_info [0].y = start_y + 5;
    beam_info [0].width = 52;
    beam_info [0].height = 5;
    beam_info [0].max = 15;
    beam_info [0].value = 3;
    beam_info [0].max_color = 1;
    beam_info [0].value_color = 9;
    // Player - Helth
    beam_info [1].x = 126;
    beam_info [1].y = start_y + 15;
    beam_info [1].width = 166;
    beam_info [1].height = 5;
    beam_info [1].max = 100;
    beam_info [1].value = 3;
    beam_info [1].max_color = 16;
    beam_info [1].value_color = 14;
    // Opponent - Punch
    start_y += 25;
    beam_info [2].x = 126;
    beam_info [2].y = start_y + 5;
    beam_info [2].width = 52;
    beam_info [2].height = 5;
    beam_info [2].max = 15;
    beam_info [2].value = 3;
    beam_info [2].max_color = 1;
    beam_info [2].value_color = 9;
    // Opponen - Helth
    beam_info [3].x = 126;
    beam_info [3].y = start_y + 15;
    beam_info [3].width = 166;
    beam_info [3].height = 5;
    beam_info [3].max = 100;
    beam_info [3].value = 3;
    beam_info [3].max_color = 16;
    beam_info [3].value_color = 2;
  }

 }
 
 function BeamPaint (int b)
 {
   // Background paint
   RawSetColor (beam_info [b].max_color);
   RawDrawRectangle (beam_info [b].x, beam_info [b].y, beam_info [b].x + beam_info [b].width, beam_info [b].y + beam_info [b].height);
   // Foreground paint
   RawSetColor (beam_info [b].value_color);
   RawDrawRectangle (beam_info [b].x, beam_info [b].y, beam_info [b].x + ((beam_info [b].width * beam_info [b].value) / beam_info [b].max), beam_info [b].y + beam_info [b].height);
  }

  function Opponent_Action (int action)
  {
    if ((g_action == 1) && (gb_action != 4))
    { // g hits above
      beam_info [1].value -= HIT_ABOVE * beam_info [2].value;
      PlaySound (6);
    }
    else if ((g_action == 2) && (gb_action != 5))
    { // g hits middle
      beam_info [1].value -= HIT_MIDDLE * beam_info [2].value;
      PlaySound (6);
    }
    else if ((g_action == 3) && (gb_action != 6 ))
    { // g hits down
      beam_info [1].value -= HIT_DOWN *beam_info [2].value;
      PlaySound (6);
      }
    
    if (beam_info [1].value <= 0)
    {
      beam_info [1].value = 0;
      BeamPaint (1);
      Wait (5);
      SetCharacterView (GetPlayerCharacter (), sides [box_side].fight_view +7);
      AnimateCharacterEx (GetPlayerCharacter (), 0, 10, 0, 0, 0);
      // player is dead
      // moving to endscreen
      Wait (60);
      NewRoomEx (20, 315, 128);
            }
      else { BeamPaint (1); }
      SetCharacterView (g_opponent, g_fightview + action);
      g_action = action;
      if (g_action <4) { g_duration = 10; }
      else             { g_duration = 50; }
    }
  
    function Boxen_Action (int action)
    {
      SetCharacterView (GetPlayerCharacter (), sides [box_side].fight_view +action);
      if (action <= 0)       { gb_duration = -1; }
      else if (action < 4) { gb_duration = 10; }
      else                 { gb_duration = 50; }
      if (action ==1)
      { // Player(gb) hits above
        if (g_action !=4) { 
 PlaySound (6);
beam_info [3].value -= HIT_ABOVE * beam_info [0].value;}
        Opponent_Action (4);
       
      }
      else if (action == 2)
      { //gb hitts middle
        if (g_action != 5) {  PlaySound (6); beam_info [3].value -= HIT_MIDDLE * beam_info [0].value; }
        Opponent_Action (5); 
      }
    
      else if (action == 3) 
      { // gb trifft unten
        if (g_action != 6) {   PlaySound (6); beam_info [3].value -= HIT_DOWN * beam_info [0].value; }
        Opponent_Action (6); 
      }
    
      if (beam_info [3].value <0)
      {
        beam_info [3].value =0;
        BeamPaint (3);
        Wait (5);
        SetCharacterView (g_opponent, g_fightview + 7);
        AnimateCharacterEx (g_opponent, 0, 10, 0, 0, 1);
        
        beam_info [1].value = 1;
        Wait (80);
        SetCharacterView (g_opponent, g_fightview + 8);
        g_opponent = -1;
        ReleaseCharacterView (EGO);
        Wait (1);
        GUIOn(1);
        GUIOn(0);
        ShowMouseCursor();
        RestoreWalkableArea (1);
        SetGlobalInt (18, 5);
        
        if (GetGlobalInt(11)==4) {NewRoomEx (18,  225,  118 );}
        
        
        
     }
     else { BeamPaint (3); }
   }


   function StartBoxfight ( int opponent, int fightview, int health, int punch, int inertia)
   {SetGlobalInt (18, 4);
     if (character [opponent].x > character [GetPlayerCharacter ()].x) {box_side = 0; }
     else                                                              {box_side = 1; }
     beam_info [1].value = 100;
     RemoveWalkableArea (1);
     g_opponent = opponent;
     g_fightview = fightview;
     g_inertia = inertia;
     SetCharacterView (g_opponent, g_fightview);
     beam_info [3].value = health;
     beam_info [2].value = punch;
     HideMouseCursor();
     GUIOff (1);
     if( cEgo.Room == 55) 
{ 
     RawDrawImage (199, BOX_GUI_Y, 344);
   }
   else
   {RawDrawImage (0, BOX_GUI_Y, 344);

} 
     BeamPaint (0);
     BeamPaint (1);
     BeamPaint (2);
     BeamPaint (3);
     RawSetColor (44371);
     if( cEgo.Room == 55) 
{ 
     RawPrint (204, BOX_GUI_Y + 8, character [GetPlayerCharacter ()].name);
     RawPrint (204, BOX_GUI_Y + 33, character [g_opponent].name);
 }
    
   else
   {RawPrint (5, BOX_GUI_Y + 8, character [GetPlayerCharacter ()].name);
     RawPrint (5, BOX_GUI_Y + 33, character [g_opponent].name);

} 
     
     Boxen_Action (0);
   }
function Box_repeatedly_execute ()
{
  if (g_opponent >= 0)
  {
    if (g_inertia > 0)
    {
      if (((g_action < 1) || (g_action > 3)) && (Random (g_inertia) < 2))
      {
        Opponent_Action (1 + Random (2));
      }
      else if (g_duration > 0) { g_duration--; }
      else 
      { 
        Opponent_Action (4 + Random (2));
      } 
    }
    if (gb_duration == 0) { Boxen_Action (0); }
    if (gb_duration > 0) { gb_duration--; }
    else
    {
      int box_action = 0;
           if ((IsKeyPressed (371) > 0) || (IsKeyPressed (55) > 0)) box_action = sides [box_side].button7;  // 7 Home (numeric pad)
      else if ((IsKeyPressed (373) > 0) || (IsKeyPressed (57) > 0)) box_action = sides [box_side].button9;  // 9 PgUp (numeric pad)
      else if ((IsKeyPressed (375) > 0) || (IsKeyPressed (52) > 0)) box_action = sides [box_side].button4;  // 4 Left arrow
      else if ((IsKeyPressed (377) > 0) || (IsKeyPressed (54) > 0)) box_action = sides [box_side].button6;  // 6 Right arrow
      else if ((IsKeyPressed (379) > 0) || (IsKeyPressed (49) > 0)) box_action = sides [box_side].button1;  // 1 End (numeric pad)
      else if ((IsKeyPressed (381) > 0) || (IsKeyPressed (51) > 0)) box_action = sides [box_side].button3;  // 3 PgDn (numeric pad)
      if (gb_action != box_action)
      {
        gb_action = box_action;
        Boxen_Action (box_action);
      }
    }
  }
}   

GarageGothic

But you're just declaring the function, not calling it from anywhere in this script

monkey0506

You don't call InitSides from within that snippet.

[EDIT:]

Garage beat me. >:( lol

cjhrules

#10
this is the function I call from the room: StartBoxfight (int opponent, int fightview, int health, int punch, int inertia);

So what should I do to get the particular  views in that room?

Edited by mod: Don't double post.


Gilbert

I didn't see you calling that function from within StartBoxFight(), unless you make another room (like you mentioned) function with name identical to one in global script (the scripts you posted were all in global script right?), which doesn't seem to be a good habit (especially when you need to call a global function from the room function).

cjhrules

Anyone know how I should modify the script?

Khris

How about adding
Code: ags
InitSides();

somewhere between
Code: ags
function StartBoxfight(...) {

and
Code: ags
}
?

Like GG said:
QuoteBut you're just declaring the function, not calling it from anywhere in this script

SMF spam blocked by CleanTalk