Use families in Objectname.value? with INI

This forum is currently in read-only mode.
  • I'm trying to make a recursive way to monitor an object's position and constantly save in in an INI. But I don't want to do every code for every object. I can't seem to explain it well, so I'll post a psuedo code:

    Normal Code for Construct:

    -[Object Name].x

    -[Object Name].y

    My Code:

    -[Family Name].x

    -[Family Name].y

    Will that work? I placed objects who's position needed to be recorded in a family. SO I'm thinking that if I just use a family, they would be all be applied to it.

    Some questions on INI:

    1. How do I get values from INI into an object's private variables which will then be used to place that object and vice versa.

  • Your still going to have to pick the individual objects, but you can use for each for that.

  • Oh I see. Thanks I'll try it and see how it goes. BTW, how would I make an NPC randomly circle around a layout? I mean.... simply randomly go around it.... like a zombie

  • simplest way would be like

    (inverted)sprite.rts is moving

    every random(10000)+ 1000 miliseconds

    sprite.rts move to position xrandom(layoutwidth) yrandom(layoutheight)

    That would be for a single sprite, you could use a family instead, or even pick a random member.

    edit:

    Note if you have a lot of objects the pathfinding may bog it down a bit, if so just use add waypoint at position.... that is if your using rts behavior.

  • I wouldn't use "for each" for going through larger families. Instead try "Pick object by value", where the object would be your family. It will pick all objects the expression you enter applies to.

    I did a little speed test for that - in my project I have the family "Ships".

    I displayed an object counter in my debug console and told Construct to create fighters (member of ships) until the fps drops below 60.

    In my code I did:

    for each (Ships)
       Ships('status') = "Idle"
          Tell ships to move to random position
          Set Ships('status') = "Roaming"
    [/code:3q3mibjp]
    
    My object count went up to close to 1.600 before my FPS dropped below 60.
    However, when I tried this:
    
    Pick (Ships) by value 'Status' = "Idle"
    etc.
    
    My object count went up to close to 16.000 before my FPS dropped below 60.
    So this is clearly faster.
  • I wouldn't use "for each" for going through larger families. Instead try "Pick object by value", where the object would be your family. It will pick all objects the expression you enter applies to.

    I did a little speed test for that - in my project I have the family "Ships".

    I displayed an object counter in my debug console and told Construct to create fighters (member of ships) until the fps drops below 60.

    In my code I did:

    > for each (Ships)
       Ships('status') = "Idle"
          Tell ships to move to random position
          Set Ships('status') = "Roaming"
    [/code:o2hte6hd]
    
    My object count went up to close to 1.600 before my FPS dropped below 60.
    However, when I tried this:
    
    Pick (Ships) by value 'Status' = "Idle"
    etc.
    
    My object count went up to close to 16.000 before my FPS dropped below 60.
    So this is clearly faster.
    

    Yes you will need a trigger, otherwise each tick it will run the line.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hmm I guess that could work now. I'll just use 1 npc for now. Anyway, how do I set the value of a textbox equal to a global variable?

    Is the mibbit chat thing broken? I cant seem to connect right now. Even with the AJAX.

  • Anyway, how do I set the value of a textbox equal to a global variable?

    Add an action, Text > Set text... and for the value: global('variable name goes here')

    like global('var'), global('i')

    If it's a numerical value, do this: str(global('variable name')) or alternatively like "" & global('variable name')

  • I wouldn't use "for each" for going through larger families. Instead try "Pick object by value", where the object would be your family. It will pick all objects the expression you enter applies to.

    I did a little speed test for that - in my project I have the family "Ships".

    I displayed an object counter in my debug console and told Construct to create fighters (member of ships) until the fps drops below 60.

    In my code I did:

    > for each (Ships)
       Ships('status') = "Idle"
          Tell ships to move to random position
          Set Ships('status') = "Roaming"
    [/code:1yvzsdlz]
    
    My object count went up to close to 1.600 before my FPS dropped below 60.
    However, when I tried this:
    
    Pick (Ships) by value 'Status' = "Idle"
    etc.
    
    My object count went up to close to 16.000 before my FPS dropped below 60.
    So this is clearly faster.
    

    in addition to the fact that you need a trigger it will add all Idle objects to the SOL JanMan needs to loop though each instance of the family so that it will only pick one at a time.

    Also Jan man why do you constantly need to be writing to the .ini file? if the player leaves the layout just write the values then constantly writing to the disk is slow.

    we also talked about this on the chat yesterday. If you have each object in the family with a private variable name your writing function would look like this.

    ->on function Save Positions

    ->for each [familyname]

    -->ini.writevalue(npc('name'),"x") value: [family name].x //the group is the NAME private

    variable of your NPC family Item = x

    -->ini.writevalue(npc('name'),"y") value: [family name].y

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)