address specific unit and variables (?)

For questions about using Classic.

Post » Sat Jul 04, 2009 9:49 am

hello folks

hmm i don't know how to start..

for an rts game:
i want to have a unit selected, check weather it has the pv "can_build" set to 1 and if so draw a "build_button" on the navbar at the bottom.

i was somehow thinking that i can set a global variable "selected_unit" set to the unit you selected or the first one if you selected multiple units. then just do something like:

if (selected_unit.can_build == 1)
build_button.visible=1
else
build_button.visible=0

does this somehow work in construct?
it's annoying when you know how to do something, but don't know how to tell construct to do it ^^

it may have something to do with getUniqueID but i can't search for that because the words are to common.

this is how i would do it in WorldEdit (warcraft3 editor) where "unit" is a variable type.

so i am basically asking how to address a specific unit (and its variables...), i guess...



thanks
B
1
G
3
Posts: 5
Reputation: 835

Post » Sat Jul 04, 2009 11:16 am

It's unecessary to try and work out how to store a "reference" to an object in events. The usual way is just to use the object-picking conditions to run the logic. For example, given the situation:

- each 'unit' has the private variables is_selected, can_build
- 'build' button should be invisible unless a selected object (is_selected = 1) can build (can_build = 1)

Then you can just take advantage of the top-to-bottom execution of events:

+ Always
-> Build button: Make invisible

+ Unit: 'is_selected' equals 1 (...picks all selected units)
+ Unit: 'can_build' equals 1 (...picks all selected units that can build)
-> Build button: Make visible (...this only runs if at least one object met the above conditions)
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Sat Jul 04, 2009 2:07 pm

so simple and it makes sense.

thanks so much :-)
B
1
G
3
Posts: 5
Reputation: 835


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests