Trouble with Attributes

Echo Magnum

  • Posts: 36
I am using an attribute to keep track of the player's direction. It is named Right.
Right is a Boolean, its default value is true because the player by default faces right.

I added to the Player the event Updated
>always
>if (right was pressed)
  -set right to true
>otherwise if (left was pressed)
  -set right to false

I added to the Player the event Keyboard
>when get_player is released
>if (right = true)
 -kill self
 -play sound powerup
 -create [Player] at ( x: [x of self] y: [y of self] ) at Middle
 -switch animation to [as animation: idle_right] for [Last Created Actor]
>otherwise if (right = false)
 -kill self
 -play sound powerup
 -create [Player] at ( x: [x of self] y: [y of self] ) at Middle
 -switch animation to [as animation: idle_left] for [Last Created Actor]

for some reason when I press left and later press the get_player button ( which is C ) the Player is loaded as default right even when I set the animation to change so that it is facing left.

I'm I missing something?

froz

  • Posts: 250
When you have problems like this, use block "print" to check if the code is being run like you think it is. For example, you can add at the beggining of when updated event: "print right as a text", then start the game, open console and see if it shows left after you pressed left. If it is still printing "false", then you know this part of your code works well and something must be wrong later. Remember to delete or deactivate print block afterwards, or it can really slow your game down.

Sunflower

  • Posts: 591
Hmm... I don't know what exactly this code does, but maybe try moving "kill [Self]" block at the end of "if" / "otherwise if" wrappers? So the actor would be killed after creating the actor.

Also, you can press tilde ("~") to show the console. Apart from the prints you can add through Design Mode at proper places, you can also see prints generated by system itself. Sometimes it's useful to check these, e.g. to make sure that there are no "null object" errors or something like that.

Echo Magnum

  • Posts: 36
This code is supposed to switch the actor "Player" to another actor that has a gun "GunPlayer". It is supposed to be made so that you can equip and un-equip your gun.

I placed Kill Self last but for some reason is sort of works when I am moving but it quickly flashes with the actor facing right first.

Also what is tidle ("~") ?

« Last Edit: June 10, 2012, 02:02:13 pm by Echo Magnum »

Echo Magnum

  • Posts: 36
where is the text show when I use the print block? I don't see it?

Sunflower

  • Posts: 591
Tilde is a character at the keybord. In typical QWERTY one it's probably situated to the left of number, under the Escape key, above Tab. In some cases something else works, from what I heard, but tilde seems to be the most typical one. O.o'

When you press it, the console should appear. That's where text is printed.

Echo Magnum

  • Posts: 36
I see the problem now, not sure how to fix it though, when I press right then the attribute right is set to true ( which is good ) when I press left then the attribute right is set to false ( which is also good ) but when I press right again the attribute is still set to false and when I press left again it is also still set to false.

It's like the attribute works the first time then gets stuck on false resulting in the character always facing one way when I try switching to the gun-player.

Should I use two attributes instead? I don't know an easy and efficient way to properly fix this without making a bunch of useless attributes and lots of complex if statements.