User Tag List

Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 27

Thread: Changing which active object the user controls

  1. #1
    Clicker Fusion 2.5

    Join Date
    Aug 2014
    Location
    Hawaii
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Changing which active object the user controls

    Hey CT gang,

    Couldn't find a hit on searching so here goes. I'm still learning different things in CTF by making my small version of Missile Command game, and I'm having difficulty figuring out how to "switch control" between one missile turret and the next. I haven't coded it yet because I thought the way I wanted to do it was a bit archaic and very tedious so I wanted to see how else it has been done before.

    This is how I would do it:
    Set global variable "active_turret" = 1
    First frame loads

    User clicks with left button
    AND active_turret = 0
    Start loop "fire left turret" 1 times

    User clicks with left button
    AND active_turret = 1
    Start loop "fire middle turret" 1 times

    User clicks with left button
    AND active_turret = 2
    Start loop "fire right turret" 1 times
    ...
    etc.
    ...

    Then each "fire x turret" loop would have their own missile objects starting at their own hot points with all the speed, angles, settings etc....
    But to me that just seems repetitive. And whenever I see repetition, I think there has to be a loop or some sort of array or something that can do this.
    Is there a way to have a user switching control between multiple active objects with out the repetitive coding necessary to do it?

    I would imagine someone has made a cowboy or shooting game or maybe a pirate game where the user had a gun in each hand or 5 cannons to choose and shoot from and they each had their own ammo, hot point for the projectile leaving, etc. etc.

    Any help would be greatly appreciated. Thanks!

    -wiggy

  2. #2
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,159
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    You're absolutely right, each time there's code-redundancy,
    it's very likely that you can do things in a better way!

    Don't know how your turret control is setup,
    anyway, you'll probably benefit from "qualifiers"
    i.e. add all of your turrets to group "player"
    then code your turret actions not on "turret" object but on "player .group"
    and add a value or flag to state which is the currently active turret

    i.e.

    turret selection

    start of frame
    >>> set "turret1" flag 0 on

    user clicks on turret 2
    >>> set "turret1" flag 0 off
    >>> set "turret2" flag 0 on
    >>> set "turret3" flag 0 off
    (this is the most redundant part, better structured ways obviously exists,
    but as long as you only have 3 turrets this would be only coded 3 times, and can be a safe and easy way)

    turret actions

    player presses fire 1
    + group.player flag 0 = on
    >>>> (group.player) fire missile

    player holds right input
    + group.player flag 0 = on
    >>>> (group.player) set angle to (angle) -1

    etc.

  3. #3
    Clicker Fusion 2.5

    Join Date
    Aug 2014
    Location
    Hawaii
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks schrodinger,

    So my turret control is basic.
    When user clicks left mouse I spawn a missile active object at the turret (I only have one).
    Then I code the missile to move towards that mouse point (x,y)
    Then when it gets there, run explosion animation,

    So now I'm thinking, how would I add another turret and allow the user to switch to it. Your statement here is interesting:
    anyway, you'll probably benefit from "qualifiers"
    I think I see what you're saying but not sure where to go for qualifiers...or is that just a term you're using haha

    But reading on, I was more confused (sorry) on this part:

    i.e. add all of your turrets to group "player"
    then code your turret actions not on "turret" object but on "player .group"
    I'm not quite sure how to add turrets to a group.. or in general add all active objects to a group.
    When you said player.group, that looks like parent.child type of syntax, so I get it, just not sure how to "group" them to begin with.
    I'm hoping its just so simple (maybe under properties of the active object?) that I'm missing how easy it really is, lol. But can you give a little more explanation on how I "group" active objects and how to reference them?

    Thanks!

    wiggy

  4. #4
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,159
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    Qualifiers are a very-very useful tool in Fusion but they are a little "hidden",
    so if you've never used them I can see my explanation must have sounded very confusing

    You can "subscribe" any active object (or active picture object) to a "qualifier",
    by selecting the object in the frame editor and going in the left "properties",
    choosing the "events" tab (the one with gridlike-excel icon)
    and clicking "edit" button on the "qualifier" row.

    A new window will pop out asking you to "add" a qualifier.
    You can choose the one that suits you better (in the example I was talking about the "player" qualifier, first of the list)
    They are all the same, so choose the icon you think more suitable for your objects group.

    So, confirm your choice, and now your object belong to a qualifier.
    Repeat this procedure for all of the objects you want to belong to the same group.

    This means that you can refer ALL of the objects belonging to this group,
    just by referencing to their single -shared- qualifier.

    In this way, you can code one single set of events for any given number of turrets,
    and this will work for all of the turrets that share this qualifier
    (no need to code multiple events for multiple objects!)

    The "flagging" part of the example was to say Fusion just to choose only one of the turrets in any given time.

    Hope this explanation was clear enough

  5. #5
    Clicker Fusion 2.5

    Join Date
    Aug 2014
    Location
    Hawaii
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is an awesome explanation, makes lots of sense!

    I'm really excited about this statement:

    This means that you can refer ALL of the objects belonging to this group,
    just by referencing to their single -shared- qualifier.
    I'm wondering if qualifiers are available to reference after you create them as an object to right click on in the Frame Editor, or does the Event Editor have another column for that object, or both, or neither?

    I'll see tonight when I get back to my computer and let ya know what issues I have trying to use it.
    Thanks!

    wiggy

  6. #6
    Clicker Fusion 2.5Fusion 2.5 MaciOS Export ModuleInstall Creator Pro
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    advaith's Avatar
    Join Date
    Jun 2015
    Location
    SF Bay Area, California, USA
    Posts
    1,324
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Qualifiers will have a column in the Event editor, but will not be in the Frame Editor.

    You can, however, make position-related events (it will show the icon in the center of the screen) and it will work for the one object instance that got affected in gameplay.

    Example: You have 2 boots and one book in the "Generic 1" group and you have the character in the Player group. You make the event "Group.Player collides with Group.Generic 1", "Select Position of Group.Generic 1 to 50,50". Then, you play the game and collide into a boot. that specific boot will move, but not any other ones.
    Attached files Attached files

  7. #7
    Clicker Fusion 2.5

    Join Date
    Aug 2014
    Location
    Hawaii
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey advaith,

    Thanks for the example.
    The behavior is not what I expected. For instance:

    Why does the book also go to where the boot went if its in the same Generic qualifier?
    Why does only the first collided book move instead of all of them if the condition is for a collision between the two groups?

    Not understanding at all, sorry!

    wiggy

  8. #8
    Clicker Fusion 2.5

    Join Date
    Aug 2014
    Location
    Hawaii
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey schrodinger,

    I have been playing with the qualifier and I'm a little stuck on how to implement it into my current game. If I have to redo it, so be it, but I'm curious if there is another way.

    Here is what I did
    1.) Created global variables "g_green_turret = 1", "g_yellow_turret = 0"
    2.) Created conditions for switching turret
    Upon pressing "A"
    +set g_green_turret = 1
    +set g_yellow_turret = 0

    Upon pressing "S"
    +set g_green_turret = 0
    +set g_yellow_turret = 1

    So now I can track which one they want active, so on to turret actions.
    I have a loop that is called for "firing the turret" that I call when user clicks mouse:

    User clicks with left button
    + Start loop "fire" 1 times

    On loop "fire"
    + Create "missile" at (0,0) from "green_turret"
    ...
    etc.


    I got stuck at that last line because I could only select Group Player. When I did, I did not know how to tell it to fire the currently active turret... almost as if I had done a full circle and was back to my original problem.
    I ran it anyway to see what would happen, and sure enough both turrets shot a missile because I was referencing Group.Player. In my mind I'm thinking it would say something like Group.Player.green_turret, or Group.Player.yellow_turret, otherwise, yeah, wouldn't both shoot a missile if I just said Group.player without specifying which turret?

    I've cleaned it up a bit, and put it back (as much as I could) to the original before making most of the changes while attempting to use the qualifiers. The globals are in there, that's about it, please take a look at my firing method and see if I need to rewrite it in order to implement the qualifiers, or please tell me this is simple and I'm simply making it very complicated

    https://www.dropbox.com/s/bmgou3okt1...mmand.zip?dl=0

    Thanks!

    wiggy

  9. #9
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,159
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    Hello wiggy,

    I don't see the other turrets in your example, did I miss something?

    Here's multiturret version:
    https://www.dropbox.com/s/ppzkfeguyw...and_1.mfa?dl=0

    I've created two additional turrets, you can select them with right mouse button.
    (to show the currently selected turret I've moved the base, obviously you can find a better solution...)
    I've used internal flags because I think they're particularly suited for this task.

    As you will see, it was very quick and very few changes were needed when using qualifiers,
    so I did'nt comment out, but if any doubt let me know!

    (EDIT: if you prefer, you could only do with a single turret active -and no qualifiers-,
    by creating other instances in runtime and giving them IDs,
    but since turrets are few, I think in this way you can have a better control on various turrets different graphics)

  10. #10
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export ModuleUnicode Add-on
    mobichan's Avatar
    Join Date
    Oct 2007
    Location
    Buffalo, NY
    Posts
    3,310
    Mentioned
    28 Post(s)
    Tagged
    0 Thread(s)
    Wiggy: even if you use Qualifiers, your code setup will be almost exactly the same. You need the redundancy to handle the different positions you spawn missiles at. So you will need 3 event lines regardless. BTW, missile command used 3 buttons to determine which turret was shooting. Are you doing something similar?

Page 1 of 3 1 2 3 LastLast

Similar Threads

  1. Changing the brightness and contrast of active object?
    By J3sseM in forum Multimedia Fusion 2 - Technical Support
    Replies: 9
    Last Post: 12th June 2013, 10:07 PM
  2. Platformer Deceleration bug with changing controls
    By retsea in forum Multimedia Fusion 2 - Technical Support
    Replies: 0
    Last Post: 16th March 2011, 03:27 PM
  3. Changing controls
    By delta9857 in forum The Games Factory 2 - Technical Support
    Replies: 4
    Last Post: 8th November 2010, 04:56 AM
  4. Beta 4: Dynamically changing controls
    By BHGames in forum iOS Export Module Version 2.0
    Replies: 6
    Last Post: 4th November 2010, 09:59 PM
  5. Changing active object direction (???)
    By JohnC in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 19th January 2008, 11:58 AM

Posting Permissions

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