Page 1 of 1

blocks switches and buttons platform help

PostPosted: Mon 8 Oct 2018, 21:52
by Larryrl
I have a platformer that is coming along nicely. But, I have a block that can be hit from the bottom by jumping like in super mario brothers. When this block is hit, it displays a little message a hint of some kind. The problem is I want to have one or two in each level and the sign read different for each block the player collides with. No matter which block, of the block type I hit, it pops up the same message. If I have to, I can duplicate the object many times, and give each object a different name, like whiteExclamationBlock1...2 etc. The only other way I know, would be to check the players coordinates and say "player is in collision with WhiteExclamationBlock" player.X() = value player.y()=value then based on the players position as to which sign is shown. I could use text objects for the hints instead of sprites if I chose to.

Is there a way to specify which instance of an object I am working with like "WhiteExclamationBlock instnace 1" or something in the events? .

Re: blocks switches and buttons platform help

PostPosted: Mon 8 Oct 2018, 23:57
by MattLB
There are a number of ways to achieve this, but perhaps the simplest is to give the block an object variable into which you can put text. For each instance, you just type in the text you want for that instance. Then when the player hits the block you just copy the text of that instance into your message box text object (or however you are showing the message).

By doing it like this you don't have to keep track of anything, just check for a collision in the conditions and then use the object variable of the colliding object to set the message text in the actions.

Re: blocks switches and buttons platform help

PostPosted: Wed 10 Oct 2018, 18:08
by Larryrl
MattLB wrote:There are a number of ways to achieve this, but perhaps the simplest is to give the block an object variable into which you can put text. For each instance, you just type in the text you want for that instance. Then when the player hits the block you just copy the text of that instance into your message box text object (or however you are showing the message).

By doing it like this you don't have to keep track of anything, just check for a collision in the conditions and then use the object variable of the colliding object to set the message text in the actions.



Thanks so much for your help. What I finally did, after my total confusion on the subject, was to create a global text object, with no text. Then when player is in collision with whiteexclamationblock delete the whiteexclamationblock and put the text obhect in it's place with the text I wanted to show for that level. Eventually I will also set a scene timer to keep the text object on the screen for only so long before it gets deleted. What was strange though, is I did it on levels 1,2 and 3 and it only worked on level1. No matter what I did it would not work on 2 or 3 even though to my naked eyes, it looked like the exact same events, so I deleted those actions from levels 2 and 3 and coppied the one from level1. I modified it so the coordinates of the created text object was the same as the whiteexclamationblock, and modified the text of the text object. Now it works on all three levels each with a different message.