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!
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.
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.
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:
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.
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.
That's no problem, amateurhour, I'm glad I could help :)
There is nothing worse than sitting for hours over something!
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:
// 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 = "";
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. : )
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:
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.
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
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?
You are writing if/else block totally wrong.
Syntax is:
if ( condition )
{
actions
}
else
{
actions
}
Or, alternatively
if ( condition ) {
actions
} else {
actions
}
If you have only one line in "actions" you may remove brackets:
if ( condition ) <---- here is NO ';' !!!
one action; <---- here is though
else
one action;
The ';' operator is the "end of statement".
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
updated with current code...
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.
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.
yeah, button is set to runscript
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.
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.
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!
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
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.
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.
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.
okay, so I removed that bottom line and plugged the following code into the proper section
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;
}
When I run the game it works fine if I'm looking or interacting with something, but as soon as I hover over an active object or hotspot with the walk or talk icon the game crashes and I get a null pointer reference error, specifically for this line
QuotelblAction.Text = action.Append(Game.GetLocationName(mx, my));
Onker: Actually, the code was already fine when you decided to post completely misplaced curly brackets. Your first "else" will generate a parse error since it's inside the if code block, not after it. And your second "function" is inside the first one. Etc.
Proper indentation helps...
function Button1_OnClick(GUIControl *control, MouseButton button) {
if (player == cChuck) Display("You are already playing as me");
else cChuck.SetAsPlayer();
}
amateurhour:
I had a "..." in my code (line 6 in your snippet) that was meant to tell you "here's where you put the lines for the other cursor modes you're using".
You can do a quick fix by using
String action = "";
in line 3 but ultimately, you'll want to add action text for eModeWalk and eModeTalkto, too.
Ah right, I didn't notice.
I meant this, right?
function Button1_OnClick(GUIControl *control, MouseButton button)
if (player == cChuck){
Display("You are already playing as me");
}
else{cChuck.SetAsPlayer();
}
////functions are seperate, duh
function Button2_OnClick(GUIControl *control, MouseButton button)
if (player == cCouch){
Display("You are already playing as me");
}
else{cCouch.SetAsPlayer();
}
////functions are seperate, duh
function Button3_OnClick(GUIControl *control, MouseButton button) {
if (player == cEvan){
Display("You are already playing as me");
}
else {cEvan.SetAsPlayer();
}
Sorry man, it's Saturday and I've had some beers. Ah well.
That's still wrong, you didn't close the else blocks.
You don't need to encapsulate a single command in {} anyway though.
Thanks Khris, I see what you mean now about line six. I had just removed it, but I get that I need to add conditions for the other actions. It's working properly now.
Thanks man!
That's still wrong, you didn't close the else blocks.
You don't need to encapsulate a single command in {} anyway though.
I do realise this, I just figured that it's obvious to close the blocks.
You indeed don't need to encapsulate a single command in {}, but it helped me to learn I guess. Plus, it works.
Nae hard feelin's :-*
You also forgot the opening braces in the first two functions.
All I'm saying is: if you post code that's supposed to help people who are "a little misguided", make sure it doesn't contain obvious errors. Helping is fine and always appreciated, confusing beginners isn't.
Everybody has their own coding style, but indentation and proper bracketing is a must, especially if misplaced or missing brackets was the reason for posting here in the first place...
No hard feelings. :)