Note that there are some explanatory texts on larger screens.

plurals
  1. PORandom number in Actionscript 3
    primarykey
    data
    text
    <p>I've been following a tutorial written for Actionscript 2, and have successfully converted it to AS 3, however on the second to last part I'm stuck. </p> <p>The tutorial here (<a href="http://www.cleverpig.com/tutorials/whackapig/whack.htm" rel="nofollow">http://www.cleverpig.com/tutorials/whackapig/whack.htm</a> step 8) has the following piece of code:</p> <pre><code>if (_currentframe==1) { // randomly choose whether or not to play if (random(100)&gt;97) { // should we tease or popup? if (random(3)&lt;1) { this.gotoAndPlay ("popup"); } else { this.gotoAndPlay (1); } } } </code></pre> <p>it is meant to add some randomness to the character's movement. After some googling I created this code in AS 3 hoping it would work.</p> <pre><code>if (currentFrame==1) { // randomly choose whether or not to play if(Math.floor(Math.random()*99)-97) { // should we tease or popup? if (Math.floor(Math.random() *3)-1) ) { this.gotoAndPlay ("popup"); } else { this.gotoAndPlay (1); } } } </code></pre> <p>When I run the program with this code the character's entire animation plays once (down, halfway up, up, hit). It is supposed to only play the first 3 frames, and repeat this.</p> <p>EDIT:</p> <pre><code>function random (n:int ) : int { return Math.floor (Math.random() * n); } if (currentFrame==1) { // randomly choose whether or not to play if(random(100)): 97 { // should we tease or popup? if (random(3)): 1 { this.gotoAndPlay ("popup"); } else { this.gotoAndPlay (1); } } } </code></pre> <p>Symbol 'hole', Layer 'Actionscript', Frame 1, Line 10 1084: Syntax error: expecting identifier before colon. Symbol 'hole', Layer 'Actionscript', Frame 1, Line 10 1008: Attribute is invalid. Symbol 'hole', Layer 'Actionscript', Frame 1, Line 12 1084: Syntax error: expecting identifier before colon. Symbol 'hole', Layer 'Actionscript', Frame 1, Line 13 1008: Attribute is invalid. Symbol 'hole', Layer 'Actionscript', Frame 1, Line 15 1083: Syntax error: else is unexpected.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload