Object Variables

For questions about using Classic.

Post » Sun Mar 20, 2011 4:42 am

Hi! I'm new to Construct and i've worked with mod programs like Warcraft III and SCII editors. I became interested in this program because i was told that it was similar in concept to the editors i was using. However, i have one question. Is it possible to make Object variables(variables that store Objects rather numbers)? Or is there some similar function to fulfill this task?
B
1
G
1
Posts: 7
Reputation: 439

Post » Sun Mar 20, 2011 7:38 am

Variables can only store numbers and text. Maybe use text in a way that helps you? (object name or such).

I don't know what you would use it for as I haven't tried the editors you mentioned, but a random guess is that maybe containers will help?
http://sourceforge.net/apps/mediawiki/c ... Containers
B
10
S
3
G
3
Posts: 110
Reputation: 2,206

Post » Sun Mar 20, 2011 11:08 am

Also, you could store the object's UID together with any info you need using a hashtable.
[url:275jbf1q]http://sourceforge.net/apps/mediawiki/construct/index.php?title=Hash_Table_Object[/url:275jbf1q]
(Look at the example)

But most of the time you won't need to store the objects. Maybe you can explain what you're trying to achieve?
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Mon Mar 21, 2011 5:32 am

Ermm...well it can be used for many instances. For example, i could use object variables to store the weapons of a character into an array and access them individually should i need it. While this can be done manually without object variables, it wouldn't be as efficient without it. Basically what i want to do with it is to be able to call it as a function to perform actions without having to duplicate the trigger for different objects.

EDIT: A good example would be what you see in Warcraft III or Starcraft 2 editors where you can store ANYTHING in a variable, from numbers to text to different types of objects. Saves alot of effort and makes your triggers more efficient. =/
B
1
G
1
Posts: 7
Reputation: 439

Post » Mon Mar 21, 2011 2:06 pm

Yes you can do that, but you have to remember that Construct isn't an editor.
Rather its more like a programing language, without the need for scripting.
So while the idea of allowing objects to be stored in other objects is doable, you cant just click a button and have it happen.
You must design a system that allows a user to do that.
A good place to start is actually a combination of Vati-nyan and tulamide's posts, a hash table in a container with an object.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Thu Mar 24, 2011 5:09 am

Ok this is what i'm having trouble with:

I'm trying to make a sports type game. All "players" use the same sprite. Players can pick up the ball and when that player collides with another player the ball will be dropped.

Now, how do i help the game determine which player is holding the ball, and how do make triggers detect which player is affected by the collision, since they're all using the same sprite?

(For example, the following trigger event "On collision between Player (Sprite) and Player (Sprite)", how do i let Construct know which Player (Sprite) i'm referring to in any conditions or actions attached to this event? For instance, i want to attach another condition which checks whether the colliding Player has the ball(which i use a private variable to determine if the player has the ball)


EDIT: The only way i can see this being done is to have separate sprites for separate players, but that would mean i need to make individual triggers for ALL functions for each player sprite, which is obviously inefficient?

EDIT2: Or am i mistaken, and that we DO need to use individual sprites for each player?
B
1
G
1
Posts: 7
Reputation: 439


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests