Sniper Game Spawning Error [as2]
- JohnCamPro
-
JohnCamPro
- Member since: Aug. 29, 2010
- Offline.
-
- Forum Stats
- Member
- Level 03
- Blank Slate
Below is my script. Unfortunately the random function isn't doing it's job. Instead the variables "SpawnX" and "SpawnY" are staying at 0. Which I set them to a few frames back after declaring, but it never returns to that frame, so I don't get why this is happening. Anyone see anything that jumps out?
onClipEvent (load) {
_root._SpawnX = Math.random()*640+699
_root._SpawnY = Math.random()*6+447
this._x = _root.SpawnX;
trace (_root.SpawnX)
this._y = _root.SpawnY;
trace (_root.SpawnY)
speed = random(8)+1;
}
- CyanSandwich
-
CyanSandwich
- Member since: Aug. 14, 2009
- Offline.
-
- Forum Stats
- Member
- Level 41
- Programmer
I don't see anything wrong there. Give us more code or perhaps a .fla dump
- JohnCamPro
-
JohnCamPro
- Member since: Aug. 29, 2010
- Offline.
-
- Forum Stats
- Member
- Level 03
- Blank Slate
Sure. This should work. I made a separate FLA with just the actions and just the enemy, for quite obvious reasons.
- CyanSandwich
-
CyanSandwich
- Member since: Aug. 14, 2009
- Offline.
-
- Forum Stats
- Member
- Level 41
- Programmer
Is there a particular reason you declared the variables on the first frame?
I got rid of the first frame actions and the _root's for the spawnX and spawnY variables and it worked.
- JohnCamPro
-
JohnCamPro
- Member since: Aug. 29, 2010
- Offline.
-
- Forum Stats
- Member
- Level 03
- Blank Slate
Oh, well thanks! I really don't have much knowledge of AS2 I'll be honest but that's what my school's criteria demands. Most of what I know was taught by my brother or read from tutorials. Anyways. Thanks!

