'Placeholder' Sprite?

For questions about using Classic.

Post » Sat Dec 04, 2010 5:58 am

Disclaimer: I've searched the FAQ, tutorials, documentation, and this forum trying to find a solution to this problem, but I don't know exactly what to call it or where to look. I'm sure it's here, I'm just new to scripting/coding and thus unfamiliar with the jargon.

The situation: I've got a 'roll' button that randomly generates a number between 1 and 20 when clicked. Each number corresponds to 1 of 20 sprites; when a sprite's number is rolled, it is generated. I've also got a 'test' button that subtracts from the generated sprite's private variables.

My question: how do I get the 'test' button to subtract from the private variables of the generated sprite without it knowing in advance which sprite it will be? Do I create some sort of 'placeholder' sprite that mimics the private variables of the generated sprite, and tell the test button to always subtract from the placeholder? If not, how do I tell the test button which sprite to subtract from?
B
4
S
1
G
2
Posts: 39
Reputation: 1,028

Post » Sat Dec 04, 2010 11:54 am

I assume that you know that actions directly after a create/spawn action will pick the newly created object. But I believe the problem here is that you're creating the object by name.

If possible you should use just different frames (for static objects) instead of different sprites. Or if it needs to be animated, use different animations. That would make your life a whole lot easier. But might not be feasible depending on what your sprites need to be able to do.

So in case you absolutely need to have different sprites, always remember what Ashley said back in 2009:

[quote:2wzky99w]The way it is, though, is that when you create an object, it doesn't really exist until the end of the next top level event or trigger. (A top level event is anything which is not a subevent of anything else - I can't remember if events in groups of events count)[/quote:2wzky99w]

Always keep that in mind when you're trying to manipulate newly created objects.

So in this case, if you have an object created by name and want to assign a certain PV to it, you could do it similar to this:

[url:2wzky99w]http://dl.dropbox.com/u/2306601/Rollit.cap[/url:2wzky99w]

I'm making use of a family and a set the PV to be changed to a negative initial value to indicate that it hasn't been changed yet.

What's also important is that you shouldn't use Button objects for creation events, since they're messing with the newly created object in a way that changes applied to it will appear one tick too late. That's the best I can explain it right now, there's a comment in the cap which should make it clearer.

Also let me mention that there is a Python-method to safely pick newly created objects. But I'm not much of a Python-user and can't recall it right now. A forum search should come up with it or somebody else will be so kind to repost it here.
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Sat Dec 04, 2010 11:56 pm

[quote="PixelRebirth":1gw3vesw]I assume that you know that actions directly after a create/spawn action will pick the newly created object. But I believe the problem here is that you're creating the object by name.

If possible you should use just different frames (for static objects) instead of different sprites. Or if it needs to be animated, use different animations. That would make your life a whole lot easier. But might not be feasible depending on what your sprites need to be able to do.

So in case you absolutely need to have different sprites, always remember what Ashley said back in 2009:

[quote:1gw3vesw]The way it is, though, is that when you create an object, it doesn't really exist until the end of the next top level event or trigger. (A top level event is anything which is not a subevent of anything else - I can't remember if events in groups of events count)[/quote:1gw3vesw]

Always keep that in mind when you're trying to manipulate newly created objects.

So in this case, if you have an object created by name and want to assign a certain PV to it, you could do it similar to this:

[url:1gw3vesw]http://dl.dropbox.com/u/2306601/Rollit.cap[/url:1gw3vesw]

I'm making use of a family and a set the PV to be changed to a negative initial value to indicate that it hasn't been changed yet.

What's also important is that you shouldn't use Button objects for creation events, since they're messing with the newly created object in a way that changes applied to it will appear one tick too late. That's the best I can explain it right now, there's a comment in the cap which should make it clearer.

Also let me mention that there is a Python-method to safely pick newly created objects. But I'm not much of a Python-user and can't recall it right now. A forum search should come up with it or somebody else will be so kind to repost it here.[/quote:1gw3vesw]

Thanks for taking the time; I'm still trying to fully grasp it, but the .cap is very helpful, as is your explanation.
B
4
S
1
G
2
Posts: 39
Reputation: 1,028

Post » Mon Dec 06, 2010 10:13 am

I toyed around with the generator and decided that, for my purposes, it was indeed much easier to simply use 1 sprite and assign each rollable object its own animation and private variables. The application I'm trying to create is a 'challenge' screen for a racing RPG; the player and opponent randomly draw a vehicle each, followed by the player choosing the race type the vehicles should participate in. Each vehicle has 3 private variables denoting its proficiency in the race types, and there are 3 'subtract' buttons, one for each race type. These buttons are set to subtract 1 from their respective private variable from both the player and opponent; when one of the two reaches 0, that object is destroyed and the button is disabled, declaring the remaining vehicle the winner.

Ideally, the player should open the application, roll the vehicles, and click on the desired race type repeatedly until one vehicle is destroyed. However, I'm running into an odd problem. I set the global variables 'RollPlayer' and 'RollOpponent' to Random(2), as well as assigning new animations to the Player and Opponent objects based on their respective global variables (0=Ford Fusion & its private variables, 1=Ford Flex & its private variables). For some reason, the subtract buttons usually don't work after I've rolled the vehicles. They work just fine beforehand (the default animation has all 3 private variables set to 2, so 2 clicks of any button will destroy both of them), but usually refuse to respond after the vehicles are rolled. I'm not sure if they're not subtracting, not destroying when they are equal to or less than zero, or something else altogether.

I've got the private variables 'RollPlayer' and 'RollOpponent' set to -1 initially, and I tried assigning all the commands to key presses instead of buttons. I'm still getting the same problem. If it would help, I can upload the .cap file, though I've never really uploaded anything other than pictures/videos, and have no idea what services to use.
B
4
S
1
G
2
Posts: 39
Reputation: 1,028

Post » Mon Dec 06, 2010 11:14 am

[quote="SAAj":2z50a0cp]I toyed around with the generator and decided that, for my purposes, it was indeed much easier to simply use 1 sprite and assign each rollable object its own animation and private variables.[/quote:2z50a0cp]

Sounds like a wise choice. :)

[quote="SAAj":2z50a0cp]I'm not sure if they're not subtracting, not destroying when they are equal to or less than zero, or something else altogether.[/quote:2z50a0cp]

Did you try running it in debug mode. Maybe you would be able to see what's exactly going wrong by monitoring the variables.

[quote="SAAj":2z50a0cp]I've got the private variables 'RollPlayer' and 'RollOpponent' set to -1 initially, and I tried assigning all the commands to key presses instead of buttons. I'm still getting the same problem. If it would help, I can upload the .cap file, though I've never really uploaded anything other than pictures/videos, and have no idea what services to use.[/quote:2z50a0cp]

While I appreciate the time you took to elaborate about the problem at hand, it's really hard to come up with any kind of solution without seeing the corresponding cap file. So I'd indeed suggest you upload it. I would recommend to get Dropbox, which quickly has become the standard around here for sharing files. It's fast and very easy to use!
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Mon Dec 06, 2010 11:41 am

[quote="PixelRebirth":2aaiq557] While I appreciate the time you took to elaborate about the problem at hand, it's really hard to come up with any kind of solution without seeing the corresponding cap file. So I'd indeed suggest you upload it. I would recommend to get Dropbox, which quickly has become the standard around here for sharing files. It's fast and very easy to use![/quote:2aaiq557]

I opened it in debug mode; seems like the private variables aren't subtracting. Thanks for the Dropbox suggestion; I can see why it's so popular. Here's the .cap: http://dl.dropbox.com/u/16313158/Gears%20of%20Car.cap
B
4
S
1
G
2
Posts: 39
Reputation: 1,028

Post » Mon Dec 06, 2010 12:06 pm

Oh, you're constantly setting the private variables when the globals are greater than -1. Those events need to be sub-events. Like this you know:

B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Mon Dec 06, 2010 12:43 pm

That solved the problem; thanks again!
B
4
S
1
G
2
Posts: 39
Reputation: 1,028


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests