User Tag List

Results 1 to 7 of 7

Thread: Creating objects by name looping through global values

  1. #1
    Clicker Fusion 2.5 DeveloperAndroid Export Module

    Join Date
    Mar 2014
    Location
    Sweden
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating objects by name looping through global values

    I'm fairly inexperienced when it comes to Fusion and I have just started working with groups and loops.
    Right now I'm trying to build a way to spawn a squad of units from data in the global strings by having string 1, 2 be "fighter", "mage" for example.
    The loop "deployObjects" is meant to create objects by the name that corresponds to the global strings through the loop index (loop index 1 fetches string 1 and creates the object with the same name).
    In my main project and in this example this method only spawns one type of unit, never both, and they are the opposite in both cases.
    It is however possible to spawn more of the same unit by editing the global strings to only contain the same unit type.

    Am I looking at some kind of scoping issue here or am I doing it wrong?

    Attachment 28951

  2. #2
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export Module
    Janette5's Avatar
    Join Date
    Dec 2014
    Location
    Western Cape, SA
    Posts
    801
    Mentioned
    58 Post(s)
    Tagged
    0 Thread(s)
    Your attachment gives me this message: Invalid Attachment specified. If you followed a valid link, please notify the administrator

    I don't really understand your explanation or why you would be using strings, so without the attachment I can't help you.

  3. #3
    Clicker Fusion 2.5 DeveloperAndroid Export Module

    Join Date
    Mar 2014
    Location
    Sweden
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Deploy objects.mfa

    Maybe that one will work better.

    The idea with using global strings is that the player has the party (rpg style) stored globally across frames.
    As it is I seem to have problems with understanding the scope and logic behind loops.
    Another example that I'm working on is this nested loop for firing bullets, it only works for one unit and sometimes on two while looping repeatedly.
    I doubt that kind of inconsistency is a part of how foreach and fast loops work. Any help is much appreciated!

    bulletloop.png

  4. #4
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export Module
    Janette5's Avatar
    Join Date
    Dec 2014
    Location
    Western Cape, SA
    Posts
    801
    Mentioned
    58 Post(s)
    Tagged
    0 Thread(s)
    More often than not you don't need to use loops.

    So Question 1. You're doing this:

    * Start of Frame
    New Objects : Create Global String A at (80,181) layer 1
    New Objects : Create Global String B at (160,181) layer 1

    Which of these factors are going to change? What information won't you know that Fusion must look up?

    Question 2: I think you're trying to do this:

    * Repeat while left mouse-key is pressed //the player is holding down the left mouse button
    + NOT Player is stopped //the main character is moving (player is stopped - negated)
    + Player: Flag 0 is off //this is optional - it's just so that you don't create a bullet 60x a second - but only 1 a second
    New Objects : Create Bullet at (0,0) from Player //now create a bullet at the location of the player
    Player : Set Flag 0 on //this is optional - it's just so that you don't create a bullet 60x a second - but only 1 a second


    * Every 01''-00 //resetting the flag set above so that a bullet fires only once a second
    Player : Set Flag 0 off


    * Number of Bullet > 0 //if there's a bullet in the frame always move the bullet in this way. (Or just give the bullet a movement like bouncing ball - set a direction, click moving at start and it will go - no code needed.)
    Bullet : Set X position to X( "Bullet" ) + 1

  5. #5
    Clicker Fusion 2.5 DeveloperAndroid Export Module

    Join Date
    Mar 2014
    Location
    Sweden
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Janette5 View Post
    More often than not you don't need to use loops.

    So Question 1. You're doing this:

    * Start of Frame
    New Objects : Create Global String A at (80,181) layer 1
    New Objects : Create Global String B at (160,181) layer 1

    Which of these factors are going to change? What information won't you know that Fusion must look up?
    Yes, obviously I've been overcomplicating things here. I wanted to avoid repeating lines as I don't know how many strings/units that will be used. Another thought was to keep the HP of each unit in the corresponding global value and fetch both through the loop index. I managed to solve this one by writing a new line for every unit name since using ONames$"group.objects" didn't work, it kind of defeated the purpose of using a loop to begin with. :P


    Quote Originally Posted by Janette5 View Post
    Question 2: I think you're trying to do this:

    * Repeat while left mouse-key is pressed //the player is holding down the left mouse button
    + NOT Player is stopped //the main character is moving (player is stopped - negated)
    + Player: Flag 0 is off //this is optional - it's just so that you don't create a bullet 60x a second - but only 1 a second
    New Objects : Create Bullet at (0,0) from Player //now create a bullet at the location of the player
    Player : Set Flag 0 on //this is optional - it's just so that you don't create a bullet 60x a second - but only 1 a second


    * Every 01''-00 //resetting the flag set above so that a bullet fires only once a second
    Player : Set Flag 0 off


    * Number of Bullet > 0 //if there's a bullet in the frame always move the bullet in this way. (Or just give the bullet a movement like bouncing ball - set a direction, click moving at start and it will go - no code needed.)
    Bullet : Set X position to X( "Bullet" ) + 1

    What I want to achieve it to have a group of different objects fire different projectiles (attackType) at the same time but at individual frequency (attackSpeed) while the player is in "movement mode" (isMoving). I've tried using a for each loop and/or switching a "is firing" flag for this but both result in having all units firing at the attackSpeed of one of the objects picked at random, I just don't know how to get them to perform the same action but with their individual qualities.
    firing.png

  6. #6
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export Module
    Janette5's Avatar
    Join Date
    Dec 2014
    Location
    Western Cape, SA
    Posts
    801
    Mentioned
    58 Post(s)
    Tagged
    0 Thread(s)
    Well it works if you just remove part of the loop:

    * Start of Frame
    Special : Start loop "deployObjects" Number of units times


    * On loop "deployObjects"
    New Objects : Create Global String(LoopIndex("deployObjects")) at (133,181) layer 1
    Group.Player : Set X position to 80 * LoopIndex("deployObjects")

    But you have the setting ticked - create at start - and that means that these objects are automatically created at start and you'll now have duplicates of them which would create a problem as well. Tick off the block - create at start, to solve that.

    ----

    You can try something like this -

    Create weapons with bouncing ball movement, which is an automatic movement, with moving at start clicked, and then you set the speed at which they should move when you create them as follows:

    Here I store 2 alterable values with the active object. The first one is Attack Type and the second is Attack Speed. I call these values when an object is created

    * Repeat while left mouse-key is pressed
    + NOT Active is stopped
    New Objects : Create "Weapon " + Str$(Attack Type( "Active" )) at (0,0) from Active
    Group.Bullets : Set direction to Dir( "Active" ) //Set the direction to the direction the active object is facing
    Group.Bullets : Set speed to Attack Speed( "Active" ) // set the speed to the alterable value stored with the active object


    Instead of saving the attack speed with the active object, it is saved with the weapon so that each weapon can have its own speed. I call these values when an object is created


    * Repeat while left mouse-key is pressed
    + NOT Active is stopped
    New Objects : Create "Weapon " + Str$(Attack Type( "Active" )) at (0,0) from Active
    Group.Bullets : Set direction to Dir( "Active" )
    Group.Bullets : Set speed to Attack Speed( "Group.Bullets" )

    I made you an example at the bottom of your .mfa - with a flag that limits how often the bullets are created. If you don't use that flag then they're created constantly. Lines 6 and 7 do the same thing - so choose which option you want and delete the other one. (That's why only one of them should be active at a time.)

    Note the SPACE after weapon "Weapon " - that's because the name of the Weapon is "Weapon 1" (Else rename it to weapon1) and remove the space.
    Attached files Attached files

  7. #7
    Clicker Fusion 2.5 DeveloperAndroid Export Module

    Join Date
    Mar 2014
    Location
    Sweden
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much for your input Janette5. The deploy loop works fine now.

    For the second one I made a "cool down" meter using two alternate values on the grouped objects to make them fire at different intervals.

Similar Threads

  1. Replies: 8
    Last Post: 3rd October 2019, 07:49 AM
  2. Replies: 1
    Last Post: 7th June 2018, 04:47 PM
  3. Replies: 1
    Last Post: 3rd March 2017, 01:32 PM
  4. Global Values & Alterable Values with same names
    By Gustav in forum Multimedia Fusion 2 - Technical Support
    Replies: 8
    Last Post: 7th November 2012, 06:15 PM
  5. Negative values in a List, and Global Values
    By aidmm in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 20th January 2007, 06:08 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
  •