Two issues; one is Hotspots, another is character-related.

Started by CapnDingo, Mon 07/09/2009 18:59:26

Previous topic - Next topic

CapnDingo

I've come from a background of light programming only to be completely stumped. I've tried everything under the sun to get the simplest of things working, but I'm very discouraged.

Tried searching the forums, came up empty.

All I wanted was a GUI textbox to display the name of the hotspot the mouse is over. I used to do this easily in earlier versions of AGS, and now it's a nightmare.

  Label1.Text = MousedOverHotspot.Name;

Well, it's pretty obvious that's what I want to set the label to my MousedOverHotspot. My problem is there's no way to actually GRAB the hotspot and declare it to MousedOverHotspot. There's no compatible declaration type with a hotspot.

I tried:

Hotspot MousedOverHotspot = Hotspot.GetAtScreenXY(mouse.x, mouse.y);

Nope. Compile error. Cannot declare local instance of managed type (?! It couldn't possibly be more cryptic). I even tried declaring it as int, object, and string just to be silly, though I knew those wouldn't work, but I was desperate.

This is becoming a lot of work for something so simple. I was hoping to hit the ground running seeing that I already had coding knowledge, only to fall face-first in the mud at my very first lines of code. :( Anyone know anything that could help?

As a bonus question (sorry, I wasn't sure whether to ask two questions in one thread or spam up the forum with two threads, so I took the lesser of two evils), is there any way at all to confine my character to only moving left/right? I have no lengthy verticality in my game and so there's no need for there to be deliberate up/down walking animations (which would waste a lot of time for my artist, not to mention I just don't want it).

At the same time, I don't just want to randomly assign one of the side views to the up/down in the event that it makes something behave weirdly (for instance, moving up and very slightly to the left, but it still detects it as up and faces the character right, thus making him not face what he was sent to).

Sorry for the novel. All help is appreciated, I've only just begun and I really don't want to quit this early.

NsMn

Just set the label's text to "@OVERHOTSPOT@" and you're set  :)

CapnDingo

Oi, are you serious? Thanks.

But I want to beat my head now. :p

Khris

Pointers need an asterisk in their declaration.

Code: ags
  Hotspot* MousedOverHotspot = Hotspot.GetAtScreenXY(mouse.x, mouse.y);


The cool thing about @OVERHOTSPOT@ is that despite the name, it'll work for Objects and Characters, too.

To answer the second question:

Code: ags
 // inside on_mouse_click / eMouseLeft

  if (mouse.Mode = eModeWalkto) ProcessClick(mouse.x, player.y-GetViewportY(), mouse.Mode);
  else ProcessClick(mouse.x, mouse.y, mouse.Mode);


Note that this won't allow the player to move up or down at all.
If you want to display only the left/right loops, there's a thread dealing with that floating around.
(The general idea is to use two views, one where the up and down loop contain the left loop frames and one where both contain the right loop frames, then use either view depending on whether the character walks to the left or right.)

CapnDingo

Yeah, sorry, I should have specified. It's not that I DON'T want to move up and down, it's that I want to maintain the left/right facing directions even when I'm moving up/down.

Only issue is the logistics, I'm not sure how I'm going to determine whether the character is moving left or right...

Thanks though.

Khris

This should work:
Code: ags
// inside on_mouse_click / eMouseLeft

  if (mouse.Mode = eModeWalkto) {
    player.StopMoving();
    int x = mouse.x+GetViewportX();  // convert to room coordinates
    if (x < player.x) player.ChangeView(LEFT);  // clicked left of player?
    else player.ChangeView(RIGHT);
  }
  ProcessClick(mouse.x, mouse.y, mouse.Mode);


Note that this way isn't perfect; if you're using complex walkable areas, the player might not walk in the direction of the click from the start.
Unfortunately, one can't switch the view during walking, so it's gets complicated quickly.

CapnDingo

Ahhh, of course. That makes sense.

If complicated movements cause problems I can always figure something out. I just needed a step in the right direction (no pun intended?). :P

SMF spam blocked by CleanTalk