loop param not working as expected - createjs

I have a single clip on the stage with an instance name of testShape. In frame 1 I have the following code:
createjs.Tween.get(this.testShape, {loop:true}).to({y:240}, 1000);
When I run this it loops infinitely as expected but what I want is for it to loop three time then stop and fire a complete event.
The docs say that the loop param...
Indicates the number of times to loop. If set to -1, the tween will loop continuously.
Which suggests I should be able to set {loop: 3} to achieve my desired result but any number value other than 0 just causes it to loop endlessly.
Can anyone advise on what I'm doing wrong or how to make a Tween loop n times before completing?
Cheers all

It looks like TweenJS 0.6.2 and earlier used a Boolean value for loops, so while you can set it to true or false, you can not put it as a number of loops. If you set it to a number, it will be converted to true.
createjs.Tween.get(obj, {loop:true}).to(…).to(…);
This behaviour was updated in version 1.0.0 of TweenJS, in September, 2017.
createjs.Tween.get(obj, {loop:3}).to(…).to(…);
I am glad you found a solution:
I got it working in the end by making each tween set up the next as it completes.

Related

Trouble understanding value vs Series in PineScript

greenCandleCount=0
if close > open
greenCandleCount := greenCandleCount+1
plot(greenCandleCount)
In the above example, greenCandleCount is a value in the first line. But, close and open are both Series of floats. So in line 3, greenCandleCount seems to get converted into series. Because the line 2 comparison operation seems to produce a Series of booleans. Somehow a single variable lying inside an if block where the expression is a Series, also gets expanded into a Series. So why does this happen?
greenCandleCount doesn't get converted to series. The way you've declared it, it was always a series variable. At the start of the next bar, greenCandleCount would be reset to 0
With the code you've provided, greenCandleCount would always be either 1 or 0 and you'd be able to reference the previous bar's greenCandleCount state the same as any other series variable ie greenCandleCount[1]
If you wish to have a variable that is only initialized once and maintains it's value across bars it must be declared with the var keyword ie
var greenCandleCount = 0
Then your code will count the number of green candles on the entire chart.
https://www.tradingview.com/pine-script-reference/v4/#op_var

Why will this loop iterate just one time not two times?

The Random node will output the random value that is between 0 to 1. The initial i value should be zero. So for the first iteration, the comparator should output a signal TRUE to let the loop iterate again. When i is 2, the loop will stop, because the random variable is smaller than 2.
So as my thinking, the loop should iterate only two times and then stop, but the answer shown to says me the loop should iterate just 1 time. Is the answer wrong or is my thinking wrong?
I ran the same code and got 2 executions of the loop, as you'd expect.
Furthermore, since the random number generator cannot return exactly 1, the code is guaranteed to take exactly 2 loop cycles.

Why is the Visual Studio debugger skipping valid lines?

I am working on a VB.NET program in Visual Studio 2017. There is a patch of code that the debugger skips completely over every time. I have rewritten it a dozen times trying to make it work. Code optimization is turned off. I have tried deleting every single file in the Solution folder and subfolders except for the source files and rebuilding from scratch. No change. Google hasn't given me a solution.
In this case, ClientList has two elements, so the .Count is 2.I want to traverse it from the last element to the first, so I use a for loop on line 209.While debugging, I verify the count is 2, so the debugger should work its way through the for loop twice. But after line 209, it jumps straight to line 228.
I included the second loop for comparison because it always debugs fine, even though it's doing the same thing, iterating through the elements of ClientList.
Can anyone solve this for me? I've spent most of the day on this and can't get any further until I have a solution.
Add Step -1 to the For-statement and it should work as expected.
For ClientIndex As Integer = ClientList.Count -1 To 0 Step -1
Excerpt from the documentation:
The default value of step is 1.
Means, without Step -1 the value of the loop counter is incremented and thus the loop never runs because 1 (ClientList.Count-1) is already greater than 0.

Optimal Method of Checking Keypresses on TI-89

for an experiment I decided to program a little game into my TI-89 using the built in program editor, however I cannot figure out an optimal method of getting keystrokes without significant delay. Currently I have:
Prgm
70→xpos
70→ypos
Loop
If getKey()=340 Then
xpos+3→xpos
PxlCrcl ypos,xpos,5,1
EndIf
If getKey()=337 Then
xpos-3→xpos
PxlCrcl ypos,xpos,5,1
EndIf
If getKey()=257 Then
Goto end
EndIf
EndLoop
Lbl end
EndPrgm
This creates an endless game loop that checks if the left, right, or delete buttons are being pressed and draw a circle left or right accordingly or end the program entirely. However, this method seems to run extremely slowly and I have seen much smoother movement in other demonstrations. Is there something wrong with my method and if so how can I improve it?
Sorry, I use a TI-84, but this method should still work.
The getKey() function is the function that is creating a delay. You only have to run the getKey() function once if you put the output into a variable. In TI-84, you can just do
getKey->K
You should be able to do exactly the same thing with TI-89.
Hope this helps!
What I usually do is use a While not() statement then check the answer afterwards.
For example
loop
0 -> X
while not(X)
do something every iteration
getKey()
if Ans: Ans -> X
Check values of X with If statements
End loop
In this way you are just executing some code (Maybe some basic addition and subtraction or a For loop to slow things down) and a single If statement on each loop of the While statement instead of checking a lot of If statements on each loop.
This serves you well and allows you to do something on each iteration of the While loop while still checking for a keypress.
Note that I usually program on TI-84s, but the idea should work much the same in the TI-89 with a bit of tweaking.

How to prompt messagebox once inside a for loop in vb.net?

Is it possible to display a single messagebox inside a for loop codes?
I am trying to but cannot successfully make it.
Please help.
Thanks in advance.
Code inside a loop, by definition, is meant to execute multiple times, for each iteration of it, so if you don't want to have multiple messages, move that call outside of the loop so it executes only once. This would be the main way of doing so, because it makes it clear that there will be ever only one of them.
Otherwise, you can condition its display, by some particular condition that's warranted to happen only once, possibly caching the result from the user. The second snippet from phadaphunk does something like that.
From you question, I get that you don't understand how it works below.
The loop is a set of instructions that must be executed "x" number of time. So everything that is in the body of that loop will be executed that number of time. Which means that if there are 5 iterations to the loop, you will get 5 messagebox.
This is how you do it if you want a different box for each iterations :
For Each x As Integer In someList
MessageBox.Show(x.ToString());
Otherwise you can't do it unless there is a certain condition that explains to the compiler at which iteration you want the message box to appear. Something like
For Each x As Integer In someList
If (x == 5)
MessageBox.Show(x.ToString());