Another picking thread

For questions about using Classic.

Post » Sat Mar 14, 2009 6:42 am

Ok I have an image, and I have set up 5 image points numbered 1-5, and I want to take 5 duplicates of the same sprite and place them on the image with the 5 image points.

Geez we really need a better way to pick from multiple instances, at least we do if you want the idiot savants like me to be able to use this thing. :P

Any way this:
[code:2m0fmwxl]System: 3 For each spot 0 ordered by spot 1 .x Ascending
> spotSet position to object citi 0 (image point spot 1 .Value('var'))
> spotAdd 1 to 'var'
[/code:2m0fmwxl]
Does not work, it places all sprites at the same image point, plus its not even getting any of the preset points, just the original "point" instead.

Yes I know, I could simply create additional objects and do it that way, but I'm trying to optimize things as much as possible. I'm already getting "out of vram" errors as it is.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Sat Mar 14, 2009 7:53 am

Give the sprite a private variable and number them 1 through 5.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sat Mar 14, 2009 3:21 pm

Or use magic pink. :P

Is there a better way than the way I was using?
I thought the for each would work like a loop, and each picked by object's x, would add 1 to private variable "var", then I could use the variable to set to the points. Evidently its not even using the variable when placing the image to the points.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Sat Mar 14, 2009 3:31 pm

Does it work if you do:

+ For Each Spot
-> Set spot position to Sprite.ImagePointX(LoopIndex), Sprite.ImagePointY(LoopIndex)
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,518

Post » Sat Mar 14, 2009 4:43 pm

Sorry nope.
The loops running fine, but it keeps putting everything on one spot. Initially I thought it was using the original "point", but now it seems its using the hot spot instead.

Anyway I figured a work around, I had each sprite spawn a text with the object unique id, then I just wrote down that info, and made an event for each unique id... works fine.

Now my next question, is there a way to get objects unique id without having to a get them at runtime?
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Sat Mar 14, 2009 4:59 pm

[quote="newt":3ckb4ueo]Or use magic pink. :P [/quote:3ckb4ueo]


Okay:

http://dl.getdropbox.com/u/529356/fivepoints.cap

No, seriously... it works. Give the sprite a variable, and number them 1 - 5. You don't need to use UID. Hell, you don't even need to make five copies of the sprite in the layout... you could Destroy On Startup and make a loop that creates five sprites and numbers their var 1 - 5.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sat Mar 14, 2009 5:28 pm

Ok... thanks, but wtf?
:D
First I haven't found anything explaining [code:2nyqp1db]"" & Sprite.Value('var')[/code:2nyqp1db].
Ok ampersand means add to the variable, but [code:2nyqp1db]""[/code:2nyqp1db] means huh?
Second, every time I add a private variable, it automatically creates an initial value no mater what I do.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Sat Mar 14, 2009 5:38 pm

[quote="newt":26ywxdpp]First I haven't found anything explaining [code:26ywxdpp]"" & Sprite.Value('var')[/code:26ywxdpp].
Ok ampersand means add to the variable, but [code:26ywxdpp]""[/code:26ywxdpp] means huh?[/quote:26ywxdpp]

Well... image points can be referred to by name or number, yeah? And they're named 1, 2, 3, 4, and 5. So I added "" to indicate that it was a string, so as to reference the point by name. Then I put in & which is the string concatenator.

[quote="newt":26ywxdpp]Second, every time I add a private variable, it automatically creates an initial value no mater what I do.[/quote:26ywxdpp]

So change it in properties. Different instances of objects can have different values in their private variables in the layout.

Or, as I mentioned before, with a loop at runtime. Either way will work.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sat Mar 14, 2009 5:54 pm

Alright I get it now, thanks.
[quote:1r76jtae]So change it in properties. Different instances of objects can have different values in their private variables in the layout.[/quote:1r76jtae]

See I didn't know that was possible, did not know that each additional object dropped on the layout could have its own specs. Hidden feature I guess.

Thanks again, now I've got tons to play with.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Sun Mar 15, 2009 4:28 am

[quote="deadeye":1cf8k451][quote="newt":1cf8k451] So I added "" to indicate that it was a string, so as to reference the point by name. [/quote:1cf8k451][/quote:1cf8k451]

That seems like a backwards and undocumented way of doing it... Can't you just use str()?
B
2
S
2
G
4
Posts: 136
Reputation: 1,722

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests