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

okay, so I removed that bottom line and plugged the following code into the proper section

Code: AGS
      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));
Co-Founder of Pink Pineapple Ink Pink Pineapple Ink
Creator of the online comic Trouble Ticket Trouble Ticket

Khris

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...
Code: ags
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
Code: ags
String action = "";

in line 3 but ultimately, you'll want to add action text for eModeWalk and eModeTalkto, too.

OG

Ah right, I didn't notice.

I meant this, right?

Code: AGS
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.

Khris

That's still wrong, you didn't close the else blocks.
You don't need to encapsulate a single command in {} anyway though.

amateurhour

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!
Co-Founder of Pink Pineapple Ink Pink Pineapple Ink
Creator of the online comic Trouble Ticket Trouble Ticket

OG

Code: AGS
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  :-*

 

Khris

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. :)

SMF spam blocked by CleanTalk