Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Anshinin on Tue 10/02/2015 03:02:23

Title: Player sprite in GUI
Post by: Anshinin on Tue 10/02/2015 03:02:23
I didn't know how exactly to word this for the title but hopefully this makes sense.

Basically I'm trying to be able to place my players sprite in the inventory GUI window so that you can see who you're playing as (like in zelda64) and if you "look at" them, you'll see their stats. (workin on rpg stuff) I'm not exactly sure where to begin with this and on top of that I have two playable characters so it'd have to be a conditional else if statement for the other character I think.

EDIT:: Forget! I'd also like the respective characters name in text to be able to display.

Thanks in advance :grin:
Title: Re: Player sprite in GUI
Post by: Slasher on Tue 10/02/2015 08:23:54
You could have this....

Conditions if player is me or him. Replace me and him with actual characters script name and Button sprite numbers etc.

Global Rep Exec with label and button on inventory gui:
Code (ags) Select

  if (player==me){
  Button34.NormalGraphic=101; // Button sprite of character
  LChar.Text=("Me");          // Characters name on label
} else if(player==him){
  Button34.NormalGraphic=106;  // Button sprite of character
  LChar.Text=("Him");          // Characters name on label
}
}


You could also use a similar condition if you click on the button or if mouse over button.

Pure example of mouse over button:
Code (ags) Select

if (gHealth.Visible==true && Button47.Visible==true)
if(Button47.NormalGraphic==516){
if((mouse.x >Button47.X+gHealth.X)&&(mouse.x <Button47.X+Button47.Width+gHealth.X)){
if((mouse.y >Button47.Y+gHealth.Y)&&(mouse.y <Button47.Y+Button47.Height+gHealth.Y)){
cChar1.SayBackground("(Try your plastic bag)");
}
}
}



Hope this helps...

Title: Re: Player sprite in GUI
Post by: Anshinin on Tue 10/02/2015 09:29:51
It worked perfectly! I haven't practically applied the hover portion of what you supplied but getting the characters sprite and name in was perfect. Only other thing is how could I implement this same LChar.Text=("Me"); into the HUD? I'm not sure where I would put this as I put the code for the inventory in the show_inventory_window function in GlobalScript.asc

Thanks again for all this btw
Title: Re: Player sprite in GUI
Post by: Slasher on Tue 10/02/2015 10:31:33
Make a new label (LChar2) and place it where required.

To duplicate a label simply use this

Code (ags) Select

if (player==me){
LChar.Text=("Me");
LChar2.Text=("Me");         
}
else (player==him){
LChar.Text=("Him");
LChar2.Text=("Him");   
}
}


or add to existing code:
Code (ags) Select

  if (player==me){
  Button34.NormalGraphic=101; // Button sprite of character
  LChar.Text=("Me"); 
  LChar2.Text=("Me");        // Characters name on label
} else if(player==him){
  Button34.NormalGraphic=106;  // Button sprite of character
  LChar.Text=("Him"); 
  LChar2.Text=("Him");         // Characters name on label
}
}


You would put this in Global Rep Exec.



Title: Re: Player sprite in GUI
Post by: Anshinin on Tue 10/02/2015 18:12:45
Okay cool it worked, only thing is when selecting the second option you can see the first options name for a split second, then it changes to who you really are. Any way to fix this?
Title: Re: Player sprite in GUI
Post by: Slasher on Tue 10/02/2015 19:11:30
Just add LChar.Text=(""); and LChar2.Text=(""); before label changes.

Could add for example:
Code (ags) Select

LChar.Text=(""); // clears text
LChar2.Text=(""); // clears text

// Now will rewrite text on labels

if (player==me){
LChar.Text=("Me");
LChar2.Text=("Me");         
}
else (player==him){
LChar.Text=("Him");
LChar2.Text=("Him");   
}
}







Title: Re: Player sprite in GUI
Post by: Anshinin on Wed 11/02/2015 01:31:42
It ended up working, though I placed the LChar2.Text=(""); in the room_Load() of the first room of the game. For some reason in global rep exec it wasnt working, but it works now :grin: thank you!!!
Title: Re: Player sprite in GUI
Post by: Slasher on Wed 11/02/2015 05:39:14
It is meant to go where you open up the inventory gui for example.
Title: Re: Player sprite in GUI
Post by: Crimson Wizard on Wed 11/02/2015 08:22:08
Slasher, I don't know what made you think you need those braces around "".
You don't have to put them. Braces are needed when you have complex operation, like 8 - (5 + 1).

Here's how you can do:
Code (ags) Select

LChar.Text = "Me";

Notice - no braces around "text";
Title: Re: Player sprite in GUI
Post by: Slasher on Wed 11/02/2015 10:02:15
Hi Crimson,

QuoteBraces are needed when you have complex operation, like 8 - (5 + 1).

I know but for some newbie they may try to do 5 + 1 without brackets because "blah" did not have them.

Surely it's better to have them in as a newbie until such time...



Title: Re: Player sprite in GUI
Post by: Crimson Wizard on Wed 11/02/2015 10:50:20
Quote from: slasher on Wed 11/02/2015 10:02:15
Hi Crimson,

QuoteBraces are needed when you have complex operation, like 8 - (5 + 1).

I know but for some newbie they may try to do 5 + 1 without brackets because "blah" did not have them.

Surely it's better to have them in as a newbie until such time...

But these are completely different problems! In the script above you used brackets to wrap whole assigned expression, not part of arithmetic operation that needs to be grouped.
You can do
Code (ags) Select

int a = 5 + 1;

and you don't need to wrap 5 + 1 in brackets here too.

Again, brackets are used when you need to control the order of arithmetic operations, only. You do not need brackets to assign the result of calculation.

I also see that Anshinin is already using this redundant syntax, and probably thinks this must be done to make it work, while it is not true.
Title: Re: Player sprite in GUI
Post by: Anshinin on Wed 11/02/2015 16:42:33
Does it actually hinder the performance of the script if the brackets are there? I'll go through and modify them to remove the redundant brackets, but I'm just curious. I'm still reading through the tutorials and whatnot on scripting for ags so I'm not super familiar with how everything works yet.
Title: Re: Player sprite in GUI
Post by: Crimson Wizard on Thu 12/02/2015 07:07:36
Quote from: Anshinin on Wed 11/02/2015 16:42:33
Does it actually hinder the performance of the script if the brackets are there?
No, of course not. It's just that they have no sense there, plus extra typing.
My general point was that it may cause wrong understanding of how the syntax works.