how to give commands to a specific instance (solved)

For questions about using Classic.

Post » Thu Mar 18, 2010 12:23 pm

I need to give some commands to a specific instance of a sprite. Let's say that I have more than 1 instance of that sprite, and I want to give an order to the sprite that has a certain private variable to move.

How do I do that?

Thank you.
B
3
G
2
Posts: 14
Reputation: 703

Post » Thu Mar 18, 2010 12:57 pm

I have a similar question:

I tried to make a function where you can push boxes around in grid movement. I didn't get very far before I noticed that the events addresses ALL of the boxes instead of the one I'm actually colliding with. Which means that when I'm pushing a box one direction, it's actually pushing all of the boxes in the same way.
In MMF2(which I have some experience with) it automatically targets the right one and the others are left alone.

What can be done to fix this? Or, what would be a more affective way to achieve the push-function?

Link to .Cap-file:

[url:3212ezam]http://falconshield.com/spel/dungeon%20construct.cap[/url:3212ezam]
B
1
G
2
Posts: 3
Reputation: 631

Post » Thu Mar 18, 2010 1:26 pm

Cristi, you should insert a "Compare Private Variable" condition into your event. If PV (Private Variable = X (X being the value you want it to pick for).

Falcon, I haven't looked at your .cap but it sounds like you should try flipping the collision condition. Instead of Player collision with Box, put Box collision with Player.
B
2
S
2
G
2
Posts: 372
Reputation: 1,794

Post » Thu Mar 18, 2010 6:42 pm

On creation of a sprite give its private variable an unique ID, I personally use the spawn object UID for that.

Then do this:
For each object <your sprite>
__If sprite private variable is equal <UID you need> -> Do stuff to sprite

[generally what Mr Wolf wrote]
B
2
G
2
Posts: 23
Reputation: 696

Post » Thu Mar 18, 2010 7:28 pm

[quote="Valis":2f96opvx]On creation of a sprite give its private variable an unique ID, I personally use the spawn object UID for that.

Then do this:
For each object <your sprite>
__If sprite private variable is equal <UID you need> -> Do stuff to sprite

[generally what Mr Wolf wrote][/quote:2f96opvx]
I don't really think they'd need to use UID. How would they know which UID they'd need anyway? I don't see how this helps picking... Also, if they are just setting the object's Private Variable to the object's UID, then that is redundant. The object's UID already stores the UID...

Now if they were pairing two objects created in the same event, they could set each one's PV to be the other one's UID (or just do that for one of them depending on what you're doing) and that would work for certain things, but in this case, no.
B
2
S
2
G
2
Posts: 372
Reputation: 1,794

Post » Thu Mar 18, 2010 8:16 pm

I have tried to use a for each object >compare variable, but... is quite slow and a better approach will be for each object created to have a unique id, like a .com hwnd so that once you get the object id you can pass it to a variable and use it when you like and how you like.

Also, a good feature is to use something like "IDvar=system.createobj.getID" to get the id and "obj(IDvar).do_stuff" for reference and commands.

I guess for now, for each and compare must do the trick..... and it does so far.
I will post this suggestion in the feature request section.

thank you all.

If any of you have any more suggestions for this issue please post them here.
B
3
G
2
Posts: 14
Reputation: 703

Post » Thu Mar 18, 2010 8:21 pm

@Mr Wolf: I didn't wrote they need, I wrote I did it that way. It is handy for me so the object remembers its parent. I merely suggested it as a good 'coding' practice.

In the even part the UID stands for any UID of the sprites object. They have to be uniqe so the picking is done right. Unique in the sens that it is right for only the ones you want to pick. You could pick more than one with such 'for each' loop.

I just thought I would elaborate on your hint as I reckoned it was to short and 3 days ago I wouldn't understand it myself. :roll:
B
2
G
2
Posts: 23
Reputation: 696

Post » Thu Mar 18, 2010 8:33 pm

Why are you guys overcomplicating things?

[quote="Cristi":3035szwf]Let's say that I have more than 1 instance of that sprite, and I want to give an order to the sprite that has a certain private variable to move.
[/quote:3035szwf]

Loops aren't needed for this. Simply compare the private variable of the sprite.
Here's a lazy example: [url:3035szwf]http://dl.dropbox.com/u/2306601/movepv_001.cap[/url:3035szwf]

Sprites with a PV Move of 1 will move to the target when you hit the space key. You can toggle the PV by clicking on the sprite.
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Thu Mar 18, 2010 9:55 pm

I agree, PixelRebirth. Hopefully that example will help him realize these things are simple...

Cristi, from speaking with you in chat and seeing your forum posts, you seem to think everything needs to be super complicated. I'd suggest you go check out the Ghost Shooter tutorial before you try to port your whole game from VB and just get confused with needless complexity. You'll save yourself a LOT of trouble if you learn how Construct works before trying to do your port.
B
2
S
2
G
2
Posts: 372
Reputation: 1,794

Post » Fri Mar 19, 2010 12:49 am

Thank you for the sample and the advices.
Problem is solved.
B
3
G
2
Posts: 14
Reputation: 703

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests