Standing on a region whilst key pressed

Started by ManicMatt, Tue 09/03/2021 11:32:50

Previous topic - Next topic

ManicMatt

Hey,

I'm trying to make a keyboard only controlled game (to be ported to consoles) and I have an eight direction script installed. If I set the conditions for standing on a region and pressing the space bar to make the character say something, and you press space to skip the speech, then the speech almost always comes up again, as the engine is detecting the space bar still being held down no matter how quickly you tap the space bar. Worse still, if I hold the spacebar down it will flicker the speech repeatedly until crashing, blaming something to do with character views, but it's probably just the speed it's going at. I've tried to KeyListener script but I can't get that to help me, I've never been much of a coder/scripter. Any help is appreciated!

eri0o

How you listening to key presses to start the dialogue?

From your description my guess would be you are using IsKeyPressed on a rep exec, which will trigger every frame.

Also, can you show a bit of code?

ManicMatt

Code: ags
function region1_Standing()
{
if (KeyListener.EvtKeyReleased[eKeySpace] && KeyListener.KeyDownTime[eKeySpace] < 100)
  cEgo.Say("I hope this works this time.");
 
    
  }



Hey eri0o, good to see you!

I also tried changing that number and trying IsKeyDown instead of released. I currently have no code at all in repeatedly execute or repeatedly execute always in my global script.

eri0o

Hey ManicMatt! It's good to see you back at games too!

So, I kinda never understood much how regions work... I THINK the standing is like a rep execute always when the character is standing... So it runs when the there's dialog on screen.

And I think keyListener (guessing, I don't know the module) uses rep execute always, so it will run and note down the spacebar being released be the character talking or not.

So I kinda think this will trigger the character speaking every time. Hopefully someone more familiar with both will answer here.

I would try to do differently, and use on_key_press and then there trigger a check for the position of the thing to interact with and trigger the interaction. Of the (hotspot maybe instead of region?) if it exists. But mostly because I don't know much about regions and the mentioned module.

ManicMatt

hmm the reason I tried using keylistener was because of the looping going on, I was hoping it might stop that! It helped slightly - if I hold the space key down it won't go nuts now, which I forgot to add I remedied that after using keylistener.

I briefly attempted hotspots, but I wasn't sure how to tell the program to check if the character is standing on a hotspot. But I guess I'll try again!

Crimson Wizard

#5
Yes, "Standing" event runs repeatedly while character is there, and the problem is that it's run right after the speech is skipped, and the skip key is still in the buffer apparently, which triggers the speech again immediately after.

If you go this way you'd have to script some way to not react to key press in same game frame it was skipped.

Quote from: ManicMatt on Tue 09/03/2021 14:53:36
I briefly attempted hotspots, but I wasn't sure how to tell the program to check if the character is standing on a hotspot.

Hotspot.GetAtRoomXY(player.x, player.y), or before AGS 3.5.0 - Hotspot.GetAtScreenXY(player.x - GetViewportX(), player.y - GetViewportY());

You may detect regions same way (Region.GetAtRoomXY).

ManicMatt

I searched for hotspot and region Region.GetAtRoomXY and stumbled across a complicated set of codes by Khris and I think it's working, phew!!

https://www.adventuregamestudio.co.uk/forums/index.php?topic=44602.0

Thanks! (To be honest I recall seeing this yesterday and it scared the hell out of me.. so I was hoping for a simpler solution, and then I forgot all about it.)

Khris


ManicMatt

I did find that, and I actually found that even more confusing haha!

SMF spam blocked by CleanTalk