Use families in Objectname.value? with INI

For questions about using Classic.

Post » Sun Nov 29, 2009 1:43 pm

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.
B
10
S
5
G
8
Posts: 203
Reputation: 4,395

Post » Sun Nov 29, 2009 1:56 pm

Your still going to have to pick the individual objects, but you can use for each for that.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Sun Nov 29, 2009 2:08 pm

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 :P
B
10
S
5
G
8
Posts: 203
Reputation: 4,395

Post » Sun Nov 29, 2009 2:20 pm

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.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Sun Nov 29, 2009 2:23 pm

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:

[code:3q3mibjp]
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.
B
3
G
3
Posts: 14
Reputation: 903

Post » Sun Nov 29, 2009 2:36 pm

[quote="impact":o2hte6hd]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:

[code:o2hte6hd]
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.[/quote:o2hte6hd]

Yes you will need a trigger, otherwise each tick it will run the line.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Sun Nov 29, 2009 3:32 pm

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.
B
10
S
5
G
8
Posts: 203
Reputation: 4,395

Post » Sun Nov 29, 2009 4:15 pm

[quote="TheJanMan":3m66eugv]Anyway, how do I set the value of a textbox equal to a global variable?[/quote:3m66eugv]
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')
B
3
S
1
G
3
Posts: 82
Reputation: 1,189

Post » Sun Nov 29, 2009 4:19 pm

[quote="impact":1yvzsdlz]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:

[code:1yvzsdlz]
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.[/quote:1yvzsdlz]

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
B
5
S
2
G
4
Posts: 632
Reputation: 2,829


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests

cron