easy switching of main player character and text gui issues (two questions)

Started by amateurhour, Wed 10/10/2012 21:53:26

Previous topic - Next topic

amateurhour

alright, I've searched "switching main character, switching player characters", checked the wiki and the manual, and seen where it's possible, and how to do if else statements depending on the character, and even found threads about sharing inventory between characters and setting the game so that when you switch, it automatically takes you to that characters room if they're in a different one...

but I can't for the life of me figure out how to physically switch the characters in game. I'm using the default game template, and all I want is either a button in the top menu or something in the right click cycle of options to switch characters. I've got three characters and I want to be able to control any of them at any given time.

The second issue I'm having is with the text field on the top status bar. I added @overhotspot@ to it so that it would display what I'm hovered over and that works great, I'd like to add a text field before that to show what the mouse action is currently set to, so for example, if you looked at a poster it would say "look at poster" instead of just "poster"

Are the only "@x@" options the five or so listed in the manual or are there more? Will I need to create one, and if so, is there a guide for that? I'm happy to read it to learn more, I just wasn't able to find much in the way of searching aside from custom gui creation.

Thanks!
Co-Founder of Pink Pineapple Ink Pink Pineapple Ink
Creator of the online comic Trouble Ticket Trouble Ticket

Crimson Wizard

Quote from: amateurhour on Wed 10/10/2012 21:53:26I'm using the default game template, and all I want is either a button in the top menu or something in the right click cycle of options to switch characters. I've got three characters and I want to be able to control any of them at any given time.
http://www.adventuregamestudio.co.uk/wiki/?title=Character_functions_and_properties#Character.SetAsPlayer

Sorry, don't have time to answer second question fully at this moment.
I may just say you'll have to make up the gui text on your own if you want custom message. Try checking 9-verbs template, they have similar functionality there.

amateurhour

Yeah, I saw the Character.SetAsPlayer() command, I just wasn't sure how to go about adding a button somewhere to let the player select which of the three characters they want to control. I'm still new to that level of scripting. I guess I can start cross referencing that with a search on "adding mouse functions to the controls"

I'd like to avoid 9verb for now as it's my first game. I played with it for a few hours earlier this week and it was a little much to just dive into for me right now.     
Co-Founder of Pink Pineapple Ink Pink Pineapple Ink
Creator of the online comic Trouble Ticket Trouble Ticket

OG

If anybody has the same problem and doesn't quite understand:

If you want to change characters via buttons, you should create a gui that includes as many buttons as you wish there to be characters. The gui should only be visible when you want it to be. ie gGui1.visible = true;/ ie gGui1.visible = false;

With the buttons, you need to make the on_click change the characters. Simple as using cwhoever.SetAsPlayer();. This will switch the characters in any situation. This will switch to the character and the character will be in the room he was last left in or started in, providing you didn't change it somewhere along the code.

if, however, you wish to change character via the use of a plain keyboard button, use this:

Code: AGS
if (IsKeyPressed(eKeyTab)){
cwhoever.setasplayer;
}


As far as object text fields go, always remember to write what you want the object to appear as via the description in the properties menu. This is easier with the 9verb - otherwise read this thread clearly.

amateurhour

Onker that makes perfect sense. Thank you!

I was going to edit the default fade in menu anyway to get rid of unnecessary stuff, and now I can add more unnecessary buttons to it to switch characters! : )

Seriously though, thanks. That gives me a strong starting point.
Co-Founder of Pink Pineapple Ink Pink Pineapple Ink
Creator of the online comic Trouble Ticket Trouble Ticket

OG

That's no problem, amateurhour, I'm glad I could help :)

There is nothing worse than sitting for hours over something!

Khris

To handle a single keypress it's better to use the on_key_press function.
IsKeyPressed will detect the current state of the key and is used to check for a key being held down (usually in repeatedly_execute).

Regarding @OVER_HOTSPOT@, it is not possible to add to the list of available tokens.
However, it's pretty simple to do it yourself:

Code: ags
// in repeatedly_execute

  int mx = mouse.x, my = mouse.y;
  if (GetLocationType(mx, my) != eLocationNothing) {   // only show action over active area
    String action;
    if (mouse.Mode == eModeLookat) action = "Look at ";
    if (mouse.Mode == eModeInteract) action = "Interact with ";
    ...
    lblAction.Text = action.Append(Game.GetLocationName(mx, my));
  }
  else lblAction.Text = "";

amateurhour

thanks Khris!

Stupid follow up question, does that just create the token? If so, how do I add it to the text field in the top menu?

Also you're very good at this. : )
Co-Founder of Pink Pineapple Ink Pink Pineapple Ink
Creator of the online comic Trouble Ticket Trouble Ticket

Crimson Wizard

Quote from: amateurhour on Thu 11/10/2012 01:21:59
Stupid follow up question, does that just create the token? If so, how do I add it to the text field in the top menu?

In Khris's example an object of type String is created. Then it is applied to the GUI Label here:
Code: ags

lblAction.Text = action.Append(Game.GetLocationName(mx, my));

lblAction is GUI Label's name, and Text is its property. It is assigned a string which is a result of string action + location name text. "Append" function makes one string of the two by concatenating them.

amateurhour

okay, so I tried writing the code to switch characters. I have three buttons on the default gui up at the top and each button has a picture of one of the three selectable player characters.

I'm trying to set it so that when you click the button, if you're already playing as the character it displays a message saying so, else it will switch the character to the correct one.

Here's what I have

Code: AGS
function btniconchuck_Click(GUIControl *control, MouseButton button) {
  if (player == cChuck);
    Display("You are already playing as me");
    else (cChuck.SetAsPlayer());
}

function btniconcouch_Click(GUIControl *control, MouseButton button) {
  if (player == cCouch);
    Display("You are already playing as me");
    else (cCouch.SetAsPlayer());
}

function btniconevan_Click(GUIControl *control, MouseButton button) {
  if (player == cEvan);
    Display("You are already playing as me");
    else (cEvan.SetAsPlayer());


I'm getting a PEO4 parse error at ";" on the first if (player == cchuck); line. If I remove the ";" it gives me another error that it's expecting one.

What am I doing wrong?     
Co-Founder of Pink Pineapple Ink Pink Pineapple Ink
Creator of the online comic Trouble Ticket Trouble Ticket

Crimson Wizard

You are writing if/else block totally wrong.

Syntax is:
Code: ags

if ( condition )
{
   actions
}
else
{
   actions
}

Or, alternatively
Code: ags

if ( condition ) {
   actions
} else {
   actions
}

If you have only one line in "actions" you may remove brackets:
Code: ags

if ( condition ) <---- here is NO ';' !!!
   one action;   <---- here is though
else
   one action;


The ';' operator is the "end of statement".

amateurhour

I was just about to reply to this myself. I added the correct actions and it compiles now, but when I click one of the three buttons on the main icon bar up top to switch characters nothing happens. I even added a display ("Blah") under one of the buttons before the if else just to see if I was getting past the initial click and nothing worked.

So basically I hover up to the icon bar, click the "Switch to chuck" button, and nothing happens. The button is set to Function     
Co-Founder of Pink Pineapple Ink Pink Pineapple Ink
Creator of the online comic Trouble Ticket Trouble Ticket

amateurhour

updated with current code...

Code: AGS
function btniconchuck_Click(GUIControl *control, MouseButton button) {
  Display("blah");
  if (player == cChuck)
    Display("You are already playing as me");
  else {cChuck.SetAsPlayer();}
}

function btniconcouch_Click(GUIControl *control, MouseButton button) {
  if (player == cCouch)
    Display("You are already playing as me");
    else {cCouch.SetAsPlayer();}
}

function btniconevan_Click(GUIControl *control, MouseButton button) {
  if (player == cEvan)
    Display("You are already playing as me");
    else {cEvan.SetAsPlayer();}
}


Basically none of that works. When I hover over one of those three buttons, and click, it just does nothing.
Co-Founder of Pink Pineapple Ink Pink Pineapple Ink
Creator of the online comic Trouble Ticket Trouble Ticket

Crimson Wizard

Is Button's Click Action is set to "RunScript"?


BTW you don't need {} after "else" since you only have one action there, similar to the one under "if". That's not a mistake, just small note.

amateurhour

Co-Founder of Pink Pineapple Ink Pink Pineapple Ink
Creator of the online comic Trouble Ticket Trouble Ticket

amateurhour

I fixed it, I'm an idiot. : )

I was writing the function as click because I copied it from something further up in the code, instead of just clicking over to "events" on the button and writing it from there.

I am again, an idiot.

Thanks for all of your help guys. I'm churning away at this demo and I'm excited to be a part of the community here. I've been working on this game for the last few weeks and it's been a nice creative outlet.
Co-Founder of Pink Pineapple Ink Pink Pineapple Ink
Creator of the online comic Trouble Ticket Trouble Ticket

amateurhour

Okay, so I combined Khris and Crimson's code for the custom text label on the gui and I'm getting an error.

Here's the code.

Code: AGS
function repeatedly_execute() {
  
  // Put here anything you want to happen every game cycle, even when
  // the game is paused. This will not run when the game is blocked
  // inside a command like a blocking Walk()

     
      int mx = mouse.x, my = mouse.y;
      if (GetLocationType(mx, my) != eLocationNothing) {   // only show action over active area
        String action;
        if (mouse.Mode == eModeLookat) action = "Look at ";
        if (mouse.Mode == eModeInteract) action = "Interact with ";

        lblAction.Text = action.Append(Game.GetLocationName(mx, my));
      }
      else lblAction.Text = "";
  
  if (IsGamePaused() == 1) return;
  lblAction.Text = action.Append(Game.GetLocationName(mx, my));
}


I get the following error.

GlobalScript.asc(74): Error (line 74): undefined symbol 'action'
which is on the last line before closing it out, the lblaction.text = action.Append line.

Thanks!
Co-Founder of Pink Pineapple Ink Pink Pineapple Ink
Creator of the online comic Trouble Ticket Trouble Ticket

Crimson Wizard

amateurhour, I don't mean to be rude, but it looks like you don't try to understand what you are doing.

First of all, what code did you combine? I did not give you any code, just tried to explain some things in Khris's code.
Your last line makes no sense there
Code: ags

lblAction.Text = action.Append(Game.GetLocationName(mx, my));

you already have exactly same line inside "if" section. Just remove the one in the end of function, and it will probably work fine.

OG

amateurhour, you are on the right path but a little misguided... Look carefully at the code here:

function Button1_OnClick(GUIControl *control, MouseButton button)
{
if (player == cChuck){
Display("You are already playing as me");
}
else{cChuck.SetAsPlayer();
}
////////////////////
function Button2_OnClick(GUIControl *control, MouseButton button)
{
if (player == cCouch){
Display("You are already playing as me");
}
else{cCouch.SetAsPlayer();
}
////////////////////
function Button3_OnClick(GUIControl *control, MouseButton button) {
  if (player == cEvan){
    Display("You are already playing as me");
}
    else {cEvan.SetAsPlayer();
}
////////////////////

It is very similar to yours, but you have certain characters in the wrong place. Try this (bearing in mind Button1/Button2/Button3 - are yours to modify.).

If you don't understand let me know. You just got the code wrong is all.

amateurhour

Onker, thanks man, I already got that working. I wasn't using the event button to set up my functions. It was simple in the end.

Co-Founder of Pink Pineapple Ink Pink Pineapple Ink
Creator of the online comic Trouble Ticket Trouble Ticket

SMF spam blocked by CleanTalk