Author Topic: Action Buttons  (Read 5200 times)

gwal

  • Regular
  • **
  • Posts: 69
  • Game Progress: Outer Space / Items
    • View Profile
Action Buttons
« on: 2006-01-02, 12:52:13 PM »
I have a few more quick questions about script, specifically about OnControllerMove.

1. Is it possible to add in a 5th action button, so that I could use X or Enter for action button 5? (Not both, but just one.) Because I was planning on adding a menu screen to my game, but...I ran out of buttons.

2. This probably has an obvious answer, but how do you set something to work (in script) using more than one action button/direction? For example, doing some sort of special move when both buttons 2 and 4 are pressed.

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Action Buttons
« Reply #1 on: 2006-01-02, 04:47:40 PM »
1. There is probably more than one way to make another action button by modifying the player object or some silly thing like that.  However, the simple way is to simply check for keypress within the script:

Code: [Select]
dim cControl = 35 'End Key

Sub Display_KeyDown(KeyCode, Shift)
if KeyCode = cControl then
            'The control has been pressed.  Do what you want here
        end if
End Sub

right now, it's set to recognize the End key (denoted by the 35 on the first line).  Follow this link to get a list of all the keys on the keyboard and their respective numbers to use: MSDN KeyCode Chart

2. For checking for more than one button being pressed at once, do something like this:

Code: [Select]
Sub Player_OnControllerMove(OldActions, NewActions)
       If (Not OldActions) And NewActions And (ACTION_BUTTON3 Or ACTION_BUTTON4) Then
              'Insert Code Here
       End If
End Sub

That will check to see if both button 3 and button 4 are pressed.  I believe that's correct anyway.  If not, try changing the Or to an And (though that probably wouldn't work. So don't try that).  If you want to combine the two and see if they're pressing the 5th button at the same time, then a bit more work is required, since pressing the 5th button doesn't call Player_OnControllerMove.
Edward Dassmesser

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Action Buttons
« Reply #2 on: 2006-01-02, 09:18:27 PM »
If you want to use the Display_OnKeyDown event you'll have to first set up the script to get events from the display, which isn't quite straightforward.  But there is sample code in the Sample Script FAQ here: http://sourceforge.net/docman/display_doc.php?docid=7777&group_id=9970.

But my suggestion would be to try to find ways to limit the number of buttons your game needs.  Most games used to be playable with just 2 buttons, and even modern game controllers usually have only 4 primary buttons (especially for 2-D games, they will often just use the 4 primary buttons).  Otherwise it starts to get difficult for the player to remember what the buttons are.  Here are som possible alternatives:
1) Instead of defining a new button for each action, use combinations of buttons.  For example, instead of making button 1 be shoot left, button 2 be shoot right, and button 3 be bomb, let button 1+left be shoot left, button 1+right be shoot right, and button 1 + down be bomb.
2) If you don't use Down, maybe you can use/remap the down key to use for something else.  Many side-scrolling games don't use down to move down, but will instead use it kind of like a button.
3) Use buttons to choose change inventory so that the same button can have multiple functions.  For example, instead of having button 1 be shoot laser, button 2 be shoot grenade and button 3 be shoot BFG, have button 1 be toggle weapon and button 2 be shoot weapon.

Oh, also, I think to check for multiple buttons, I think an adjustment would be necessary on durnurd's script:
Code: [Select]
If (Not OldActions And (ACTION_BUTTON3 Or ACTION_BUTTON4)) <> 0 And _
   ((NewActions And (ACTION_BUTTON3 Or ACTION_BUTTON4)) = _
   (ACTION_BUTTON3 Or ACTION_BUTTON4)) Then
...
I think that code will ensure that the code only executes when the player is pressing button 3 and button 4 now and was not pressing both those buttons before.

gwal

  • Regular
  • **
  • Posts: 69
  • Game Progress: Outer Space / Items
    • View Profile
Re: Action Buttons
« Reply #3 on: 2006-01-03, 10:50:24 AM »
Thanks for the info. Since my game is sidescrolling I think I'll probably just use the down button for my menu screen. My reason for asking about two buttons at once was for doing some sort of special move, but I think a problem with the way it works currently is that it would activate other Button 2 and 3 actions. So I have one last question. How do you set something (such as the bottom code above) to work for only those keys, meaning it would be activated when: pressing action buttons 2 and 3, but nothing else?

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Action Buttons
« Reply #4 on: 2006-01-03, 12:59:03 PM »
If you're talking about script code, checking for 3 and 4 and nothing else is even simple than what we already have:
[code]
If (Not OldActions And (ACTION_BUTTON3 Or ACTION_BUTTON4)) <> 0 And _

gwal

  • Regular
  • **
  • Posts: 69
  • Game Progress: Outer Space / Items
    • View Profile
Re: Action Buttons
« Reply #5 on: 2006-01-05, 11:55:10 PM »
I would have replied earlier, but I've been working on other aspects of my game. So anyway, right now when I try to use the most recent script, (using ACTION_BUTTON2 and ACTION_LEFT), it only works when I press the 2 buttons at the exact same time. What I'm trying to do is something like this. [not actual code]
Code: [Select]
Sub Player_OnControllerMove
 If left is being pressed then
   If button 2 is being pressed Then DoFireButton3
So I know it should look something like this, but I don't know which lines of script to use.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Action Buttons
« Reply #6 on: 2006-01-06, 06:40:58 AM »
OK, let me try to work out the logic of the statement I posted above to see if it should work.  It was supposed to activate when you pressed both buttons even if you had one of them pressed in the previous frame.  It sounds like you're getting it to happen only when neither of them were pressed in the previous frame.

OldActions | NewActions | Not OldActions And 3 | Final
0
3
3
True
1
3
2
True
2
3
1
True
3
3
0
False

In the table above, I assumed that there were two buttons whose values were 1 and 2 (so the actiosn value would be 3 when they are ORed together).  As indicated by the "Not OldActions And 3" column, the code will trigger when NewActions says that you are pressing both buttons only when you weren't already pressing both buttons.  I just tried this myself in a test project and it works.  I pressed Shift and then (later) while holding shift I pressed Alt and held it down.  This triggered a message in the debug log to appear, but only once.  Then I released and pressed Alt repeatedly while holding shift and it triggered some more messages.  Isn't that what you want?

gwal

  • Regular
  • **
  • Posts: 69
  • Game Progress: Outer Space / Items
    • View Profile
Re: Action Buttons
« Reply #7 on: 2006-01-21, 02:44:16 PM »
I would have posted a reply earlier, but I've been busy, and I also haven't had too much of a chance to work on my game. I decided just to use the spacebar instead of spacebar + direction for casting spells (thats what the key will be used for). There's a couple reasons I did this. First of all, I had already planned on using a menu screen, so it wasn't that hard to configure the script to work with only one magic key. The second reason is that when I tested the game using spc+direction for spells, I often ended up using the wrong attack, just because it was hard to remember the right key combination while dodging enemies.

It doesn't seem like this would have presented too much of a problem, but my game has 13 different spells, some of which have radically different effects, so it is much simpler to use one spell key.

Zorb Burger

  • Guest
Re: Action Buttons
« Reply #8 on: 2006-01-21, 02:45:50 PM »


Editd:  sry man did no mean offense, you anit pissed me off yet... ;)
« Last Edit: 2006-01-21, 02:48:58 PM by Zorb Burger »

gwal

  • Regular
  • **
  • Posts: 69
  • Game Progress: Outer Space / Items
    • View Profile
Re: Action Buttons
« Reply #9 on: 2006-01-21, 02:49:33 PM »
Yep, thats about the truth of the matter.
(but not really, I meant I've been studying for finals)