Position changing every second

orYan

  • Posts: 47
So i am trying to make an actor go down by 16 pixels (relative to its original position) every 1 second and have come up with this (in the picture)

i used to get an error but now it loads and my actor just moves off screen to the left

and is there a way to stop the repeated positioning when a collision is detected? the tutorial shows a different version and i dont know how to connect the collision event to a block behaviour...if thats even possible

EDIT...i did change the y to x's and still not change


« Last Edit: January 28, 2013, 05:42:02 pm by orYan »

orYan

  • Posts: 47
okay now its going up...no matter if i use -16 or +16

rob1221

  • *
  • Posts: 9473
Try the timer under "when created" instead.  The block should also use Y and 16 since positive is down.

orYan

  • Posts: 47
a positive integer for y would position it lower than its original position?

theabbott

  • Posts: 271
First off i wouldn't encourage you to use a periodic time block (do every..) in the Always event - this is a great way to cause headaches down the line and will lag your game in no time. I'd put that in a separate custom event and just put the trigger in the Always event.

A solution would be to make a <If Collided?> boolean attribute and set it to False when created and then when your actor collides you set it to True, then in your code you could use:

If Not <If Collided>
     do every 1 second
     Make actor go down by 16pxls 

orYan

  • Posts: 47
it still goes up and it doesnt move in increments..its just zooms offscreen...im trying to get it to move down 16 pixels every second (until a collision with another actor or the bottom of the scene)

orYan

  • Posts: 47
First off i wouldn't encourage you to use a periodic time block (do every..) in the Always event - this is a great way to cause headaches down the line and will lag your game in no time. I'd put that in a separate custom event and just put the trigger in the Always event.

A solution would be to make a <If Collided?> boolean attribute and set it to False when created and then when your actor collides you set it to True, then in your code you could use:

If Not <If Collided>
     do every 1 second
     Make actor go down by 16pxls

i wanted to do something like this actually...it makes more sense...how do i change the attribute to true when the collision happens? is there an example i can look at with the updated version with collision events?

« Last Edit: January 28, 2013, 06:04:59 pm by orYan »

orYan

  • Posts: 47
okay so i tried it with the boolean attribute created <if collided>...the pictures below are the collision events and the always event...when i test it it just zooms up offscreen instead of down... and it doesn't progress every second..

Tuo

  • *
  • Posts: 2469
I'm not 100% sure what you are trying to do. It sounds like you want it to go down, jumping by 16 pixels until it hits the bottom and then turn around and come back up until the same thing. If you want it to end when it hits the bottom, just use 0 as the attribute when it hits the bottom instead of -16. Doing it all in one attribute saves a lot of hassle ;).
Don't look to me but rather to the One who is the reason for what I do. :)

If you need help, send me a PM. Even if I haven't been on in the forums in ages, I still receive those messages via email notifications. You can also reply to any of my forum posts, regardless of the age (especially if I created it), and I will likely reply.

If you want to see the programming behind certain types of games, feel free to check out my "Demo-" games on StencylForge (http://community.stencyl.com/index.php/topic,16160.0.html)

orYan

  • Posts: 47
Because you removed the "do every 1 seconds" block.

Try this. It's the same as your initial blocks, just migrated to the Created event as Rob recommended.

It works exactly as you desired on my end with this. Just make sure you have gravity turned off for your actor.

haha and i found a little problem as well....i was doing EXACTLY what was being recomended here and it wasn't working (it kept going up)...turns out if i restart stencyl it works..i dont know why but how am i supposed to know if my coding is wrong or if i just have to restart...should i reinstall stencyl? im on windows 8 

« Last Edit: January 28, 2013, 07:48:33 pm by orYan »

orYan

  • Posts: 47
I'm not 100% sure what you are trying to do. It sounds like you want it to go down, jumping by 16 pixels until it hits the bottom and then turn around and come back up until the same thing. If you want it to end when it hits the bottom, just use 0 as the attribute when it hits the bottom instead of -16. Doing it all in one attribute saves a lot of hassle ;).

oh no it doesnt have to come back up..just stop at a collision while its doing down (the bottom of the screen or another block)

they will be able to control left or right as it goes down like tetris...is there a way i can "lock" the falling actor piece so that after maybe .5 seconds after it stops from a collision (its stops being re positioned lower and lower by 16) you can mtove it left or right anymore? I want a little time in between so people can move it left or right just as it stops if they are fast enough (like tetris lol)

« Last Edit: January 28, 2013, 07:51:18 pm by orYan »

Meestar

  • Posts: 654
Just add in a "Do after x seonds" with whatever time you want and move the stop collision code there.
PM me if you require help.  I'm always glad to help out!

orYan

  • Posts: 47
Just add in a "Do after x seonds" with whatever time you want and move the stop collision code there.

what do i "do after x seconds"...is there a behaviour to disable the keyboard input and "lock" the actor in place so that the collision mechanics to destroy adjacent blocks can occur and next piece can start falling and be controlled...

or do i put this in a conditional way..for example..

i created a boolean attribute for if the actor is collided...default setting is false

if <collision> is true
(insert behaviour here to create a 1 second window for the actor to be move right or left one more time after collision or something of the like)
if left/right is down
move actor left/right by 16
do after 1 second
set position to y of self
"lock position?" (so that the collision calculations can be made...determining with colored blocks are touching what)


otherwise
set position to fall every second by 16
if left/right is down
move actor left/right by 16


and the collision event

if bottom of self is collidied
set <collided> to true
otherwise
set <collided> to false

orYan

  • Posts: 47
and with the collided attribute...would i have to make an attribute for every block on screen? all the blocks will be following the same fall by 16 if no collision on the bottom is detected...how can i do that with all the blocks

Meestar

  • Posts: 654
When <collision> becomes <true>:
  Do after <x> seconds
    Set lock position to <true>

ALWAYS:
  if <NOT lock position>
    if <left/right was pressed>
      set <x> to <(X of Self)-/+16> (-16 for left, +16 for right)

When <Self> collides with something else:
  if bottom of actor is hit
    set collision to true

Do Every <1> seconds:
  If <NOT lock position>
    set <y> to <(Y of Self)+16> for <Self>
  otherwise
    cancel

All this goes into actor behavior and should be attached to the block actors.

« Last Edit: January 29, 2013, 01:08:48 pm by Meestar »
PM me if you require help.  I'm always glad to help out!