User Tag List

Results 1 to 6 of 6

Thread: Cycling through weapons?

  1. #1
    No Products Registered

    Join Date
    Jun 2007
    Location
    Kent, UK
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cycling through weapons?

    I know how much you all love helping out with problems so I've another question for you.

    My brother is making a game where you walk around picking up weapons which you can use in the game. If you press "1" then it selects weapon 1, pressing "2" selects weapon 2 and so on.

    Well he wants to create it so if you press a button (eg "+") then it will cycle through the weapons and pick the next one. This would be easy(ish) if you started the game with all the weapons but as you pick them up along the way then you might not have them all.

    So you have weapons 1, 3 and 4. "1" is currently selected. When you press "+" it should check and realise you don't have "2" so it should set the weapon to "3". How can we do this?

    With my limited knowledge I can create it but it requires massive amounts of code. Is there a way it can be done using loops or something like that requiring only a few lines of code, and if so how would I do it?

    Thanks!

  2. #2
    No Products Registered

    Join Date
    Sep 2006
    Location
    Germany
    Posts
    861
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Cycling through weapons?

    Create global values for each Weapon as Ammo Counters like AmmoWeapon1,AmmoWeapon2 etc and add "CurrentWeapon"

    add

    "+" is pressed --> add 1 to global value CurrentWeapon

    and then add

    + CurrentWeapon = 1
    + AmmoWeapon1 = 0
    ----> Add1 to global value CurrentWeapon

    Repeat for all weapons. You can use a loop as well.

  3. #3
    Clicker

    Fusion 2.5 DeveloperFusion 2.5 DeveloperFusion 2.5+ DLCiOS Export ModuleSWF Export Module
    xhedgehogx's Avatar
    Join Date
    Nov 2007
    Location
    NY, USA
    Posts
    743
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Cycling through weapons?

    A counter works too, but internal or global values is better.

    "+" is pressed ->Add 1 to counter.
    "-" is pressed ->subtract 1
    Counter=1 set weapon to srifle
    Counter=2 set weapon to pistol.

    But use maVados it's better.

  4. #4
    No Products Registered

    Join Date
    Jun 2007
    Location
    Kent, UK
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Cycling through weapons?

    That takes too long.

    That would mean I'd need an individual piece of code for each weapon and another bit to check if you have the next weapon.

    That's like 20 pieces of code if you have 5 weapons. He's planning on having about 8 or 9 which is about 72 different conditions.

    Isn't there some way of having it so it'll check it and pick the next available one in a few lines of code? Or am I in over my head to be trying to do this?



  5. #5
    Forum Moderator Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleSWF Export Module
    DavidN's Avatar
    Join Date
    Jun 2006
    Location
    Boston, MA, USA
    Posts
    4,044
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Cycling through weapons?

    You would be going about it the wrong way by cycling through and checking for the "next" available weapon on each individual condition.

    Instead, you could have some form of data storage object (I find the List handy for things like this, with the "hide on start" set to true so that it doesn't interfere with the game) and keep the available weapons in that, then have the +/- keys change the selected item in the list and update the selected weapon depending on the contents of the selected row.

    As the hidden List won't display anything itself, you would also need to have a separate display on the screen that updates depending on what the list object contains and which row is highlighted.

  6. #6
    No Products Registered

    Join Date
    Jun 2007
    Location
    Kent, UK
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Cycling through weapons?

    Snail, that is spot on perfect.

    Thank you so much! (Now to figure out how you did it :P)

Similar Threads

  1. Nested Loops and cycling properly
    By rubes in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 26th January 2013, 04:48 PM
  2. Cycling string object colors through code
    By mobichan in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 28th December 2011, 02:34 PM
  3. Cycling thru animations
    By bassguitar19 in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 13th October 2009, 08:30 PM
  4. Cycling/Scrolling through an inventory help
    By Atherton in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 16th July 2009, 02:24 PM
  5. Colour cycling
    By RayMarble in forum The Games Factory 2 - Technical Support
    Replies: 3
    Last Post: 11th September 2008, 05:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •