Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Assignment Button Help  (Read 3528 times)

0 Members and 1 Guest are viewing this topic.
Assignment Button Help
« on: November 23, 2013, 01:46:09 am »
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
Alright so im working on a zelda game and have 2 buttons to assign stuff like bow and arrow and boomerang and stuff to
(C button and V Button.)
each weapon has a number assigned to variables global.CButton and global.VButton. so for the boomerang i could have in the C key press
Code: [Select]
///////////////BOOMERANG////////////////////
if global.CBut = 1
{
BOOMERANG()
}
///////////ARROWS///////
if global.CBut = 2
{
ARROWS()
}
//////////////////////BOMBS///
if global.CBut = 3
{
BOMBS()
}

now in a menu thats how i assign stuff. if you click C on a menu button it changes the value to the number of the item. this leaves me with 2 problems though

C and V can both have the same item assigned. and in zelda games if i was to have boomerang on one and bow on the other and i set the boomerang to the button bow is on, they would swap places on the buttons. so what im asking since i have no idea to go about this without tons of lines of code..

if CButton is trying to equal VButton, how do i get VButton to = the old C value and C to equal the old V like in all the zelda games where you cant have the same item assigned at once.

GML code would be the best help. although if you talked through how the system would work i may be able to convert it into code that way. because once i have the system designed in english its easier to transfer into code. thank you all in advance!
-Richie
Logged
Re: Assignment Button Help
« Reply #1 on: November 23, 2013, 02:57:27 am »
  • *
  • Reputation: +12/-2
  • Offline Offline
  • Gender: Male
  • Posts: 4849
One way of doing it without really digging into your system:
Code: [Select]
CurrentCBut;

if (global.CBut != global.VBut)
{
      if global.CBut = 1
     {
             BOOMERANG()
             CurrentCBut = 1;
      }
///////////ARROWS///////
       if global.CBut = 2
       {
            ARROWS()
            CurrentCBut = 2;
       }
//////////////////////BOMBS///
       if global.CBut = 3
       {
              BOMBS()
              CurrentCBut = 3;
       }
}
else if (global.CBut == global. VBut)
{
      global.VBut = CurrentCBut;
}



What happens is this:  Your C Button is at 3 but you V Button is at 6.  You move your menu cursor to set C to 6 but you already have V set to 6.  V will then take your old CurrentCBut value of 3 and C will take the value of 6.  Thus, the numbers swap.

The thing is that you need to put checks and sets (setting and checking the globals) into separate code from the C press code.  You should try having code in your say your HUD or Inventory handling object.  Moving your cursor sets a cursorTemp variable to each number.  Then, when you press C or V, it does the check WHILE still in the menu to make sure they don't equal each other.  If they don't match, then it set's your C Button to an equipped weapon for C.  Same for V.

I am trying to explain clearly as possible but it's hard without seeing how you handle your inventory and hud and such.  With my Zelda games, I try to be as easy to follow as possible.  Instead of hardcoded numbers such as what you are doing, I use a string something like this:

C Press Event while NOT in the inventory
switch (global.CItemEquipped)
{
     case "arrows":
     {
          if (global.arrows > 0)
          { 
                shoot_an_arrow_code or script here
          }
          else
          {
               play_error/empty_sound_effect
           }
           break;
       }
       case "boomerang":
       {
            boomerang_code_here or script
            break;
        }
}


So on and so forth.  This way, I can program how an item works in a script.  When it is ready to test, I add a case for that item in the switch event.  It could be personal preference but I believe you should be using a SWITCH instead of 20 IF checks.  It is much cleaner code and is less code(which is better for Game Maker).

Anyway, just trying to give you some insight.  Like I said, I could do better if I saw exactly how your item system worked.
Logged
  • Super Fan Gamers!
Re: Assignment Button Help
« Reply #2 on: November 23, 2013, 04:10:24 am »
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
Well my system isnt the cleanest but at this point it functions correctly and to change it would need way to much work for the simpler of code for just this. although your system did give me a very good idea on how to work it into my code that i will be trying shortly. so thank you! My code is messy and not annotated and all that stuff that i really shouldnt but it works.. im not an expert. aha. well thank you for this, as it sparked an idea on how to put this in
Logged
Re: Assignment Button Help
« Reply #3 on: November 26, 2013, 10:13:14 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 13
This is just an idea, but y not do it using some sort of lookup.

u could have an array that goes like

stuff[0] = BOOMERANG
stuff[1] = BOMBS

then u could go like stuff[cbut] or stuff[vbut] to call it using script_execute or event_user.

ie. if(cbut >= 0) { script_execute(stuff[cbut]); }

then to switch u only need to swap the values of cbut and vbut
Logged
Re: Assignment Button Help
« Reply #4 on: November 26, 2013, 11:32:13 pm »
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
Thats actually partially how i completed this. I didnt use arrays but i didnt completly use the solution given above. sorry i forgot to change this to solved though!
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.047 seconds with 47 queries.