Linking GUI's to GUI's and character selecting, and anything else

Started by , Fri 30/01/2009 01:37:51

Previous topic - Next topic

ShadowRifter666

I am attempting to create a mix of rpg and mystery AGS game, though I'm not great at scripting.
At the moment I am trying to create a character selection screen using GUI's, so far I have created all the visual aspects, but now I need to link the image GUI's to the next GUI screen and from there the final image GUI to the selected character.

Code: ags

function Male_Button_OnClick(GUIControl *control, MouseButton button)
{

}


The other GUI is called
Code: ags
GUI:Male_class


So it goes kinda like:

Gender: Male/Female}
Class: One of 3 Classes} from then on playing the game with the selected character class.

From what I have gathered from other posts I can use a fade in/out option to bring up the first GUI, and there is a script "SetPlayerCharacter (CHARID)" that maybe used to select the character. only problem is bringing it all together and the linking of the GUI's before starting the game with a specific character.

I think that is everything

Khris

Something like this should work:

Gender GUI has two buttons (male ID: 0, female ID: 1), both have their function set to gender_OnClick:
Code: ags
int gender;  // 0: male  1: female

function gender_OnClick(GUIControl *control, MouseButton button) {
  if (button != eMouseLeft) return; // allow only left-clicks
  gender = control.AsButton.ID;
  if (gender) {  // female?
    bClass1.NormalGraphic = SLOT1;
    bClass2.NormalGraphic = SLOT2;
    bClass3.NormalGraphic = SLOT3;
  }
  gGender.Visible = false;
  gClass.Visible = true;
}


Step by step:
-set int variable "gender" to ID of the button
-if female was selected, change button images on class selection GUI to female images (buttons start out with male images)
-turn off gender GUI, turn on class GUI

Similarly for the class GUI:
Code: ags
int class;  // 0: Warrior  1: Thief  2: Sorcerer

function class_OnClick(GUIControl *control, MouseButton button) {
  if (button != eMouseLeft) return; // allow only left-clicks
  class = control.AsButton.ID;
  gRace.Visible = false;
  // set player character
}


You can use two methods to reflect the selected gender or class:
Either use player.ChangeView(...) to permanently change the player characters view
or use .SetAsPlayer(...) to change the player character to one of the six previously created.

You can e.g. use characters 0-5 with 0 being male warrior, 1 being male thief, etc. and 5 being the sorceress.
Then call
Code: ags
  character[gender*3+race].SetAsPlayer();


Edit: renamed 2nd OnClick to "class_OnClick" instead of "race_OnClick".

ShadowRifter666

Thanks for that, I tried out using the second code there, seemed the most simple to understand. well here are the initial results just for selecting a gender

Code: ags

int Gender_select;  // 0: Male_Button  1: Female_Button

function Male_Button_OnClick(GUIControl *control, MouseButton button) {
  if (button != eMouseLeft) return; // allow only left-clicks
  gender = control.AsButton.ID;
  Gender_select.Visible = false
  Male_class.Visible = true;
  // set player character
}

function Female_Button_OnClick(GUIControl *control, MouseButton button)
{
if (button != eMouseLeft) return; // allow only left-clicks
  class = control.AsButton.ID;
  Gender_select.Visible = false
  Female_class.Visible = true;
  // set player character
}


I have probably changed something badly, i keep getting the error "Size of identifier does not match prototype" for the
Code: ags
int Gender_select;  // 0: Male_Button  1: Female_Button


I forgot these details last time.

The first GUI to access (gender selection) is called "Gender_select", that one contains two buttons "ID:0  Male_Button"   "ID:1  Female_Button"

The other two GUI's are "Male_class" and "Female_class" and each contain similary named buttons "ID:0  Beast"   "ID:1  Warrior"   "ID:2  Thief"

The ID's are the same for both GUI's

Khris

See, that's exactly what I wanted to avoid: You have two GUIs for the class selection (just one is needed) and lots of duplicate code.

If you set up one class selection GUI with the three male images on the class buttons, all you need to do after the player selected female is to change the three buttons' images to female ones before displaying the GUI. (That's what I've done in the first piece of code, Button.NormalGraphic is set to another sprite slot to change the image. Just replace SLOT1/2/3 with the number of the female class sprite slots.)

Also, you seem to have misunderstood me: the two pieces of code take care of the gender and class selection respectively, they aren't meant for male and female buttons.
You can assign one OnClick function to multiple buttons, that's why there's the *control parameter: to determine which control was clicked.
So put "gender_OnClick" in both the male button's and the female button's OnClick textfield.
Then put "class_OnClick" in all three class buttons' OnClick.

The error occurs because you are trying to declare an int with the same name as an existing GUI pointer ("Gender_select"). Since you've named the GUI "Gender_select", AGS automatically sets that up as global variable of type GUI* to make the GUI accessible in script.

ShadowRifter666

ok, right I sorted out the OnClick so i got the right one to each button.

Now looking at what you said about changing the SLOT 1/2/3, when you say sprite slots what do you mean? is it the number of sprites used from the sprite tab, or one of the other tabs, character, view.  ???

Also another error has been thrown up "Undefined token 'bClass1'", i'll take a guess that I need to define bClass in relation to the sprite slots. though not sure about that

Khris

Exactly, just put in the numbers from the sprite manager.

You'll have to replace "bClass1/2/3" with the names of the three class buttons on the class selection GUI.
Those lines simply change the images on the buttons.

(I'm still assuming that you're using three male/female pictures you've put on buttons to let the player select a class.)

ShadowRifter666

Right that bit worked well now got
Code: ags

int gender;  // 0: male  1: female

function gender_OnClick(GUIControl *control, MouseButton button) {
  if (button != eMouseLeft) return; // allow only left-clicks
  gender = control.AsButton.ID;
  if (gender) {  // female?
    FBbutton.NormalGraphic = 57;
    FWbutton.NormalGraphic = 8;
    FTbutton.NormalGraphic = 69;
  }
  gGender.Visible = false;
  gClass.Visible = true;
}


got yet another error, this one is "Undefined  token 'gGender' "
i assume this means that I need to change the name to mean th GUI name that I want to make not visible. If that is right, may get the same error for the  "gClass.Visible"

Khris

Exactly, just replace gGender and gClass with the names of your GUIs.

ShadowRifter666

ok, i got it working so it appears properly, but at the moment it seems that the gender select option doesn't appear first, only the female classes appear now. Gonna try and sort out what you suggested so I'm only using one GUI for the classes, though i think i need to delete the old class GUI's first then create a new GUI for both gender classes.

If you code explain the simple way of going about this that would be good, i think that it would be implemented by setting it up with male of female classes first then having it change depending on which class was selected, but i have no clue how to achieve that

The final code I have now with the 2 class GUI's are
Code: ags

int gender;  // 0: male  1: female

function gender_OnClick(GUIControl *control, MouseButton button) {
  if (button != eMouseLeft) return; // allow only left-clicks
  gender = control.AsButton.ID;
  if (gender) {  // female?
    FBbutton.NormalGraphic = 57;
    FWbutton.NormalGraphic = 8;
    FTbutton.NormalGraphic = 69;
  }
  Gender_select.Visible = false;
  Female_class.Visible = true;
}

int class;  // 0: Warrior  1: Thief  2: Sorcerer

function class_OnClick(GUIControl *control, MouseButton button) {
  if (button != eMouseLeft) return; // allow only left-clicks
  class = control.AsButton.ID;
  Female_class.Visible = false;
  // set player character
}


So i need to reduce it down to one class GUI, then  set the player character without a character appearing before it has been selected

ShadowRifter666

Ok, thanks for your help so far, there are still just a few minor things to iron out
the code stands now as
Code: ags

int gender;  // 0: male  1: female

function gender_OnClick(GUIControl *control, MouseButton button) {
  if (button != eMouseLeft) return; // allow only left-clicks
  gender = control.AsButton.ID;
  if (gender) {  // female?
    BST.NormalGraphic = 57;
    WAR.NormalGraphic = 8;
    THF.NormalGraphic = 69;
  }
  Gender_select.Visible = false;
  gClass.Visible = true;
}

int class;  // 0: Warrior  1: Thief  2: Sorcerer

function class_OnClick(GUIControl *control, MouseButton button) {
  if (button != eMouseLeft) return; // allow only left-clicks
  class = control.AsButton.ID;
  gClass.Visible = false;
  // set player character
}


this is with only 2 GUI's, one for gender, one for class.

the game runs but appears to start with the male class select GUI open, although the seperate GUI is no longer there, after that one is clicked on the GUI switches to the gender select GUI and continues correctly from there, i just need to now remove the class select GUI that appears first and remove the characters that appear onscreen before the character is selected.

Matti

Quote from: ShadowRifter666 on Sun 01/02/2009 21:32:06
i just need to now remove the class select GUI that appears first and remove the characters that appear onscreen before the character is selected.

In the GUI's panel you can change the appearance and e.g. select "normal, initially off". As for the character: Just set character.Visible to false in the beginning and to true when a class or the gender is selected.

ShadowRifter666

ok so the GUI no longer appears,
you say put the
Code: ags
character.Visible = false 

at the beginning, where would be the beginning, and would the code apply to all 6 characters, and what is the code to select one character to appear and become the main character

Matti

Quote from: ShadowRifter666 on Mon 02/02/2009 03:13:32
you say put the
Code: ags
character.Visible = false 

at the beginning, where would be the beginning

Just put it in the room's beforefadein-section.

Quote from: ShadowRifter666 on Mon 02/02/2009 03:13:32
[...] and would the code apply to all 6 characters, and what is the code to select one character to appear and become the main character

Well, the command is for one character only but you can just write it for all 6 characters. The code for one character to appear is the exact same, just set it to "true" instead of "false"...

To make a character the player character use character.SetAsPlayer();

EDIT:

You don't have to make 6 characters. Just use ONE player character and change its look assigning one of six views to it using Character.ChangeView(view).

ShadowRifter666

ok so if i was to change the character view instead of having seperate characters would i be able to assign different actions to each view, rather than have them assign to seperate characters?

Khris

You can either directly check for the player character's view:
Code: ags
  if (player.NormalView == 1) {
    ...
  }
  else if (player.NormalView == 2) {
...

or reuse the existing variables holding the gender and race.

Of course you'd have to make them global variables in order to access them from room scripts.
Just remove the declarations from the global script and add them back via the Global Variables pane.

ShadowRifter666

lots of help so far, you covered things that I haven't even thought about yet.
just to go over the old, to change the character view, between 1 of 6 through the starting GUI gender_select, then gClass. how do I link that to the
Code: ags
Character.ChangeView()

at the moment I have it as
Code: ags
Character.ChangeView(class)


but keep getting the error "Must have an instance of the struct to access a non-static member"

Khris

You still have the selected gender and class stored in the variables of the same names.
To transform their values into 1-6, you can use
  gender*3 + class + 1:

                   class
         | beast | warrior | thief
gen.     |  (0)  |   (1)   |  (2)
-----------------------------------
male (0) |   1   |    2    |   3
-----------------------------------
fem. (1) |   4   |    5    |   6

Character.ChangeView(int view) can't be called, you have to call the ChangeView() function of the actual instance (of type Character), in this case: player
Code: ags
  player.ChangeView(gender*3+class+1);

ShadowRifter666

Ok I can implement that alright, just hit a minor snag, the views were arranged in the wrong order, i couldn't change the ID tags on them, so i deleted them but now I keep getting moved straight onto View 4 when creating new Views, though I have created View 1 but not View 2 or 3.
Any ideas?

ShadowRifter666


ShadowRifter666

OK the character selection at the start works perfectly
just experimenting with the
Code: ags
 if (player.NormalView ==

and found that the display text I am attempting doesn't work properly.
I am using the default code left my the cEgo character to try and change what happens when the character looks at themselves
Code: ags
function cChar1_Look()
{
  if (player.NormalView == 1, 2, 3)(
  Display("Damn, I'm a good looking Guy!"));
  
else if (player.NormalView == 4, 5, 6)(
  Display("Damn, I'm a good looking Girl"))
}


as you can see i am trying to use it so that the Display affects each gender, no matter which character, by trying to make it affect only the view

SMF spam blocked by CleanTalk