Complex arrays

Get help using Construct 2

Post » Tue Feb 28, 2012 4:07 am

[QUOTE=0plus1] Is it possible then to set the unique ID to something arbitrary?[/QUOTE] You can make an equivalent of an arbitrary unique ID by assigning a custom value or string to an instance variable. Then you can pick the instance by comparing the instance variable. It works the same as picking by UID. Just be aware that if there's more than one instance with that same value they will be picked as well.Animmaniac2012-02-28 04:10:25
Scirra Employee
B
129
S
45
G
15
Posts: 705
Reputation: 15,413

Post » Tue Feb 28, 2012 1:57 pm

@Animmaniac Are you sure you can?

I created a instance variable on my object (Which is always one) but I can't find any event that picks it! There is pick all pick nth intance.. but not pick by instance variable.. Can you explain a little better?
B
29
S
9
G
6
Posts: 525
Reputation: 8,294

Post » Tue Feb 28, 2012 2:01 pm

The question you have to ask yourself is why you want to pick a specific instance instead of another. By answering this question you'll find how to pick it.
For example if you want to pick a specific instance because it's underneath the cursor
[code]+Mouse: is over Sprite
-> Sprite: set myCustomID to 1[/code]

B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Tue Feb 28, 2012 2:06 pm

@0plus1: Compare instance variable
Then due to how events work, only the instances with the value you are comparing gets picked/filtered.

Also be sure to check the section "Picking/selecting" in the how do I FAQ, all this has already been treated in several topics.Kyatric2012-02-28 14:08:35
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Tue Feb 28, 2012 2:07 pm

@0plus1 you use a "Compare instance variable" condition for picking. I think you need to understand better how picking works, every event that reference an object is picking, not just the conditions that start with "Pick".

You can get more information here:
http://www.scirra.com/manual/75/how-events-work
Scirra Employee
B
129
S
45
G
15
Posts: 705
Reputation: 15,413

Post » Tue Feb 28, 2012 2:12 pm

@Yann @Animmaniac

Ok I see, but it's not what I want, so I explain better myself.
I am accostomed to "normal" game engines where I could select an object by its name regardless if there were 0,1 or 1000 with the same name.

I basically have this.

I'm selecting a string out of 50 with tokenat.
On the layout there are 50 insvisible object (all on the same position) which have the same name as the 50 possitble strings that I select with token.

I need to: select "string from tokenat" object -> set visible

I think it should be possible to do this but I can't find a solution.. I mean I should put 50 if condition but it's a tedious and stupid way of working the problem.

Ideas?

Thanks
B
29
S
9
G
6
Posts: 525
Reputation: 8,294

Post » Tue Feb 28, 2012 2:19 pm

Ok, I think we are running in circle, you should describe a bit more about your game, the solution might be quite simple, but just asking for some specific feature might not be the correct angle to tackle this problem.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Tue Feb 28, 2012 2:21 pm

You want to select only one of those 50 objects and make it visible, or you want to select all objects?
Scirra Employee
B
129
S
45
G
15
Posts: 705
Reputation: 15,413

Post » Tue Feb 28, 2012 2:30 pm

It's the second time the forum errors me and I lose 10 minutes of writing..

@Yann I'll try to explain myself better.
I'm making an educational application for handicapped children and I need to procedurally generate a question on startup.

Let's make an example:

var pool = "book,table,spoon,lamp";
var answer = tokenat( pool , floor( random( tokenCount(pool ,",") ) ), "," );
//On the layout there are four hidden objects called (book,table,spoon,lamp) each of them has at least 10 frames, so I can't create only one object and then calling a random frame.

I now need to: System set object called answer visible

Basically I have 50 invisible objects and I need to make one visibile.

@Animmaniac only one of those 50 objects and make it visible0plus12012-02-28 14:31:25
B
29
S
9
G
6
Posts: 525
Reputation: 8,294

Post » Tue Feb 28, 2012 3:41 pm

You could very well use only a single sprite with different animations.
On startup you select a random instance and set it to use the animation of your choice.
Capx for creating a random anim Sprite

Now what you want is to have sprites already spawnt along the layout apparently.
Commented capx for this
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 22 guests