[SOLVE] Custom GUIs Button (Arrow Direction)

Started by Arjunaz78, Thu 15/12/2011 03:42:37

Previous topic - Next topic

Arjunaz78

I've create a game with no character in it. The game similar to/or like-Myst games that only can move using custom gui arrow key button on click (total 4 arrow button GUI's, including forward,backward,right and left direction).

The question is, can i use a different code to make a player move on all direction without put a long script to it, because it got messy & confusing to myself to edit it along with other and many different games room section,currently i've create total of 19 rooms that include some of arrow gui button on certain room and all of 4 arrow GUI's button on other certain room.

Below is a one of the function on that arrow GUI's button that i use it on GlobalScript.

Button4 is a left button direction.

Code: ags

function Button4_OnClick(GUIControl *control, MouseButton button)
{
    if (player.Room == 3) {
    
      player.ChangeRoom(5);
    }
 
    if (player.Room == 5) {
    
      player.ChangeRoom(4);
    }
 
    if (player.Room == 6) {
      
      player.ChangeRoom(7);
    }
    
    if (player.Room == 8) {
      
      player.ChangeRoom(11);
    }
    
    if (player.Room == 12) {
      
      player.ChangeRoom(7);
    }
}


That means i've to put full/bucket of code on whole function in it while i create a new room right?
That's why i want to know if i can use a different code style (maybe using ARRAY?? or Modules?? or custom Global Variables??) or just continue put the whole of code in it.

THX.

..In the making of Silent Hill: The Hospital..

https://www.facebook.com/ArjunazGamesStudio

Khris

#1
Put this at the top of the global script:

Code: ags
int room[4];  // 0: left, 1: forward, 2: right, 3: back

function SetupMovement(int left, int forward, int right, int back) {

  room[0] = left;
  bLeft.Visible = (left > 0);

  room[1] = forward;
  bForward.Visible = (forward > 0);

  room[2] = right;
  bRight.Visible = (right > 0);

  room[3] = back;
  bBack.Visible = (back > 0);
}


Call the button to move left "bLeft" and put this in its OnClick:

Code: ags
function bLeft_OnClick(GUIControl *control, MouseButton button)
{
  player.ChangeRoom(room[0]);
}


Same for the other buttons, just change the index of the room[] array.

To set up the room connections, the easiest way is to use the global before-fadein event.
Just add this at the end of the global script:
Code: ags
function on_event (EventType event, int data) {

  if (event == eEventEnterRoomBeforeFadein) {

    if (player.Room == 1) SetupMovement(2, 3, 4, 0);  // left, forward, right, back
    if (player.Room == 2) SetupMovement(0, 5, 1, 0);
    ...
  }


Edit: array size corrected

Arjunaz78

Now..it works..thank you very much khris..  :)
..In the making of Silent Hill: The Hospital..

https://www.facebook.com/ArjunazGamesStudio

Arjunaz78

Owh..one more problem trigger now..

I just follow & use the code as you told me before..but the wierd thing comes like picture that i link it below..

http://imgur.com/Qcs6m

Well..below is the code that i've been use..

at the top of the global script i've use:

Code: ags
int room[3];

function SetupMovement(int left, int forward, int right, int back) {

  room[0] = left;
  Button4.Visible = (left > 0);

  room[1] = forward;
  Button1.Visible = (forward > 0);

  room[2] = right;
  Button3.Visible = (right > 0);

  room[3] = back;
  Button2.Visible = (back > 0);
}


For the button On Click i've use:

Code: ags
function Button4_OnClick(GUIControl *control, MouseButton button)
{
 player.ChangeRoom(room[0]);
}

function Button1_OnClick(GUIControl *control, MouseButton button)
{
 player.ChangeRoom(room[1]);
}

function Button3_OnClick(GUIControl *control, MouseButton button)
{
 player.ChangeRoom(room[2]);
}

function Button2_OnClick(GUIControl *control, MouseButton button)
{
 player.ChangeRoom(room[3]);
}


..and finally at the end of the Global Script i've use:

Code: ags
function on_event (EventType event, int data) {

  if (event == eEventEnterRoomBeforeFadein) {

    if (player.Room == 2) SetupMovement(0, 0, 0, 3);  // left, forward, right, back
    if (player.Room == 3) SetupMovement(0, 2, 5, 4);
    }
}


What the real error that cause it? did i miss something?
..In the making of Silent Hill: The Hospital..

https://www.facebook.com/ArjunazGamesStudio

Gilbert

When you declare int room[3];, the array only has 3 entries, i.e. with indices 0, 1 and 2.

If you want to have it taking values from 0 to 3 (i.e. there are 4 entries) you have to declare int room[4];.

Arjunaz78

..In the making of Silent Hill: The Hospital..

https://www.facebook.com/ArjunazGamesStudio

Khris


SMF spam blocked by CleanTalk