Player character switch GUI

Started by Mats Berglinn, Mon 20/06/2005 20:45:43

Previous topic - Next topic

Mats Berglinn

I'm working on a GUI as a test for switching between characters for the player. Two of my future games (after Caribbean Mysteries) will have more than three playable characters (in my test game there are five).

Let's say we have five characters: A male adult croc, a young monkey, a female adult zebra, another male adult croc (with a purple hat) and a female croc kid. There are five GUI buttons that representives the playable characters.

How do you script that when you are playing the first adult croc (EGO) and clicks on his GUI button nothing will happen or maybe execute a DisplaySpeech commando: "Hey, you're already playing as me."?

I can't seem to find any matching commando in the Manual for that you're playing EGO or MONKEY or whoever.

strazer

Quote
How do you script that when you are playing the first adult croc (EGO) and clicks on his GUI button nothing will happen or maybe execute a DisplaySpeech commando: "Hey, you're already playing as me."?

AGS v2.7:

Code: ags

  if (player == cEgo) cEgo.Say("You're already playing as me.");
  else cEgo.SetAsPlayer();


AGS <=v2.62:

Code: ags

  if (GetPlayerCharacter() == EGO) DisplaySpeech(EGO, "You're already playing as me.");
  else SetPlayerCharacter(EGO);

Candle

* Candle wishes he had strazer brains in a jar so he could just hook something up to it and tap all that knowledge he has for games..

Mats Berglinn

#3
Thanks, Strazer! Good thing that you told me in both version kinds because I still using 2:62 because Proskito's SCUMM templates doesn't work so well in 2.7 and I haven't got used to the new scripting commandos yet.

Edit

I've got a new problem: I made a GUI with a button that will activate the change characters GUI but when I try to click it nothings happening. I think it's probbly that you got to use the pointer cursor to work (I use the regular Sierra interface for the testing GUI game) but the problem is that I don't know how to script so that when the cursor goes over GUI, it changes to the pointer just like you can get the mouse cursor to change when over the Regular Sierra Iconline. Just one detail: The Activate Character Selection GUI is always on.

TheMagician

QuoteJust one detail: The Activate Character Selection GUI is always on.
I thought you want to make :
Quotea GUI with a button that will activate the change characters GUI
Shouldn't it be turned off then at the beginning?

However, as far as I know you don't have to use the pointer cursor to click on a button. As long as the player clicks the left mouse button it doesn't matter whether he is in look, walk or pointer mode.

If you want, you can change the cursor's appearance as soon as it hovers over the GUI by adding some lines to the repeatedly execute of your global script, (in AGS 2.62) something like:

====

if ( (GetGuiAt(mouse.x,mouse.y) == 777) && (GetGlobalVariable(1) == 0) ) {
Ã,  SetGlobalVariable(1,1);
Ã,  // put the number of the current mouse mode into a variable
Ã,  // change mouse cursor to the pointer mode
}
else if ( (GetGuiAt(mouse.x,mouse.y) != 777) && (GetGlobalVariable(1) == 1) ) {
Ã,  SetGlobalVariable(1,0);
Ã,  // change the cursor back to the mode it was before (using the variable)
}

====

777 would be the GUI where the button for actiavting the character GUI is located.

The script uses global variable 1 to prevent the repeatedly execute from running all the time but only once when you hover on or off the GUI.

I don't know how your script for activating the character GUI looks right now, but in general, you have to set the button's (the button which will activate the character GUI)  "on click" value in the GUI editor to "Run Script".
Then, in the "Interface_Click" function of your global script add the code to open the character GUI.

Hope that helps.
Stefan

Mats Berglinn

#5
Oh silly me, I didn't thought that I didn't told enough detail.

Here's the script:

Code: ags

 if (interface == GUI3) {
 
 if (button == 0) {
Ã,  Ã, if (GetPlayerCharacter() == EGO) DisplaySpeech(EGO, "You're already playing as me.");
Ã,  Ã, 
Ã,  Ã, else{
Ã,  Ã, SetPlayerCharacter(EGO);
Ã,  Ã, GUIOff (GUI3);
Ã,  Ã, SetDefaultCursor();
Ã,  Ã, }
Ã,  Ã, }
 if (button == 1) {
Ã,  Ã, if (GetPlayerCharacter() == KOKO) DisplaySpeech(KOKO, "You're already playing as me.");
Ã,  Ã, else{ 
Ã,  Ã, SetPlayerCharacter(KOKO);
Ã,  Ã, GUIOff (GUI3);
Ã,  Ã, SetDefaultCursor();
Ã,  Ã, }
Ã,  Ã, }
 if (button == 2) {
Ã,  Ã, if (GetPlayerCharacter() == ZIRI) DisplaySpeech(ZIRI, "You're already playing as me.");
Ã,  Ã, else{ 
Ã,  Ã, SetPlayerCharacter(ZIRI);
Ã,  Ã, GUIOff (GUI3);
Ã,  Ã, SetDefaultCursor();
Ã,  Ã, }
Ã,  Ã, }
 if (button == 3) {
Ã,  Ã, if (GetPlayerCharacter() == KAJ) DisplaySpeech(KAJ, "You're already playing as me.");
Ã,  Ã, else{ 
Ã,  Ã, SetPlayerCharacter(KAJ);
Ã,  Ã, GUIOff (GUI3);
Ã,  Ã, SetDefaultCursor();
Ã,  Ã, }
Ã,  Ã, }
 if (button == 4) {
Ã,  Ã, if (GetPlayerCharacter() == SOF) DisplaySpeech(SOF, "You're already playing as me.");
Ã,  Ã, else{ 
Ã,  Ã, SetPlayerCharacter(SOF);
Ã,  Ã, GUIOff (GUI3);
Ã,  Ã, SetDefaultCursor();
Ã,  Ã, }
Ã,  Ã, }
 if (interface == GUI4) {
Ã,  if (button ==0){
Ã,  GUIOn(3);
Ã,  SetMouseCursor(6);
Ã,  }



TheMagician: I meant that I made a GUI that activates the GUI which you switch the characters with. The activating GUI is always ON while The Character Selection GUI is only on when you clicked on the other GUI (I call them GUI4 and GUI3). It's sort of like the inventory in Sam and Max. You click on a GUI button with the box to open up the inventory window. Sorry for being so confusing! One correction: It's not "on click" in the GUI Editor but "Left Click".Ã,  Also the GUI buttons are already on Run Script.

strazer

  if (interface == GUI3) {

    if (button == 0) {
      if (GetPlayerCharacter() == EGO) DisplaySpeech(EGO, "You're already playing as me.");
      else {
        SetPlayerCharacter(EGO);
        GUIOff (GUI3);
        SetDefaultCursor();
      }
    }

    if (button == 1) {
      if (GetPlayerCharacter() == KOKO) DisplaySpeech(KOKO, "You're already playing as me.");
      else {
        SetPlayerCharacter(KOKO);
        GUIOff (GUI3);
        SetDefaultCursor();
      }
    }

    if (button == 2) {
      if (GetPlayerCharacter() == ZIRI) DisplaySpeech(ZIRI, "You're already playing as me.");
      else {
        SetPlayerCharacter(ZIRI);
        GUIOff (GUI3);
        SetDefaultCursor();
      }
    }

    if (button == 3) {
      if (GetPlayerCharacter() == KAJ) DisplaySpeech(KAJ, "You're already playing as me.");
      else {
        SetPlayerCharacter(KAJ);
        GUIOff (GUI3);
        SetDefaultCursor();
      }
    }

    if (button == 4) {
      if (GetPlayerCharacter() == SOF) DisplaySpeech(SOF, "You're already playing as me.");
      else {
        SetPlayerCharacter(SOF);
        GUIOff (GUI3);
        SetDefaultCursor();
      }
    }

  }

  if (interface == GUI4) {
    if (button ==0) {
      GUIOn(3);
      SetMouseCursor(6);
    }
  }

Mats Berglinn

Strazer, I already had enough of braces, it's just that I only showed the scripts for MY GUIs, not the ones that already existed in the Default Template.

Anyway, I tested the character switch GUI and it worked like a charm. It's just the Small GUI button (GUI 4) that doesn't work. It's supoused to turn on the Character Selection GUI (GUI 3) but it doesn't.

strazer

It's because the second-to-last bold closing brace I added is missing in your code:

Code: ags

    if (button == 4) {
      if (GetPlayerCharacter() == SOF) DisplaySpeech(SOF, "You're already playing as me.");
      else {
        SetPlayerCharacter(SOF);
        GUIOff (GUI3);
        SetDefaultCursor();
      }
    }

// missing closing brace here so GUI4 gets included in GUI3:

    if (interface == GUI4) {
      if (button ==0) {
        GUIOn(3);
        SetMouseCursor(6);
      }


Use proper indentation and you will catch such mistakes better.

Mats Berglinn

Oh, ok. I see. Well, it works now. Thanks for the help.


SMF spam blocked by CleanTalk