How to make a new arrowkey press trump an old one...?

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

User avatar
Gizmog
Metal King Slime
Posts: 2622
Joined: Tue Feb 19, 2008 5:41 am

Post by Gizmog »

Kind of, yeah. That's my basic point, is that no matter what you do, something's going to trump something else. But the benefit of doing it with tags or whatever, to make a slimy comparison, is that you have all the votes before you inaugurate someone. Like I said, I haven't ever tried this so I don't know the precise advantages and disadvantages, but to use your code as an example..

Code: Select all

### Right Arrow ### 
 
      if((keyval(key:Left) == 0) && (keyval(key:Up) == 0) && (keyval(key:Down) == 0)) then( 

..that's a lot of work to check that other buttons aren't being pressed at the same time. And where you're walking in the same "step" as you're polling the inputs, you're changing the situation for the next questions in the sequence?

I don't know exactly what I'm smoking, but suppose you were making a shooting game. A game where you can't walk and shoot at the same time. You could do

Code: Select all

If (KeyVal Key:Shoot >1)
then (
 SetTag (Shoot,on)
 Shoot
 )

if (KeyVal Key:Move >1)
then (
 if (CheckTag (Shoot,off))
 then (Move)
 else (Aim)
 )
or

Code: Select all

script,TakeInputs,begin
if (KeyVal Key:shoot >1)
then (ReceivedShootInput := 1)

if (KeyVal Key:Move >1)
then (ReceivedMoveInput := 1)
end

script,ProcessInputs,begin
if (ReceivedShootInput)
then (
  if (ReceivedMoveInput)
  then (
    Aim
    Shoot    
    )
  else (
   Shoot
    )
elseif (ReceivedMoveInput)
then (Move)
end
I guess the difference is largely organizational. If you wanted to change what trumped what in one case, you'd have to copy-paste all of the inputs around and hope that nothing in the order-of-operations breaks. In the other case, you're just copying the end results around which makes you less likely to break something?

I feel like there's a HUGE point I'm forgetting or something I'm screwing up.

EDIT: Oh! I see my problem! In the first example, you've already shot BEFORE you've aimed. So if you were facing down, and in the same tick pressed Right+Fire, you'd fire and then turn right and die. In the second example, by waiting till all the inputs are in, you'd do the (hopefully more correct) aim THEN fire!
Last edited by Gizmog on Thu Nov 12, 2015 5:11 am, edited 1 time in total.
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

I think maybe you want something like...

Code: Select all

wantdir := -1
if      (keyval(key:left)  && hero direction == left)  then (wantdir := left)
else if (keyval(key:right) && hero direction == right) then (wantdir := right)
else if (keyval(key:up)    && hero direction == up)    then (wantdir := up)
else if (keyval(key:down)  && hero direction == down)  then (wantdir := down)
else (
    if      (keyval(key:left))  then (wantdir := left)
    else if (keyval(key:right)) then (wantdir := right)
    else if (keyval(key:up))    then (wantdir := up)
    else if (keyval(key:down))  then (wantdir := down)
)
Pretty similar to what Giz was suggesting: first figure out wantdir, taking into account priorities, and then act one it.
Last edited by TMC on Thu Nov 12, 2015 6:05 am, edited 1 time in total.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

Okay cool. Well I think I'll spend a bit of time trying stuff. I was just thinking when it really comes down to it many older style controllers/joysticks don't even allow for multiple directions to be held simultaneously. It's more of a keyboard thing. So I might just be sweating things too much haha.

EDIT: I messed around with some of the suggestions and got some different effects but still not what I wanted as an end result. This was for the most part to be expected though. The mechanics with the strafing work really great as is and I can deal with the inconsistency in directional priorities.
Last edited by sheamkennedy on Fri Nov 13, 2015 3:39 am, edited 1 time in total.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Post Reply