Discuss Scratch

ZiqwerkelSharda
Scratcher
25 posts

Variable on a delay?

Is there a way to make a variable the same as another variable which is constantly updated, but as it was half a second in the past? E.g. if Variable 1 goes from 1 to 2, I want Variable 2 to have the value of 1 for a half-second longer before it turns to 2.
deck26
Scratcher
1000+ posts

Variable on a delay?

waituntilnotval2=val1wait0.5secssetval2toval1
ZiqwerkelSharda
Scratcher
25 posts

Variable on a delay?

Pardon me if I'm wrong, but doesn't that code simply set val2 to be equal to val1 every half-second? I'm looking to be able to make a sprite “follow” the player character through this method.
PutneyCat
Scratcher
500+ posts

Variable on a delay?

You could maybe use a list to store all the val1 values for the half second.

If the half-second doesn't need to be super-precise just experiment with the max length of the list so that it ends up storing about a half second worth of values.

foreveraddval1tolistiflengthoflist>max length - experimentthendelete1oflistsetval2toitem1oflist

Last edited by PutneyCat (Nov. 17, 2018 10:20:19)

deck26
Scratcher
1000+ posts

Variable on a delay?

ZiqwerkelSharda wrote:

Pardon me if I'm wrong, but doesn't that code simply set val2 to be equal to val1 every half-second? I'm looking to be able to make a sprite “follow” the player character through this method.
Sorry, you're right.

@PutneyCat probably has the right idea.

Powered by DjangoBB