-
What's wrong with my code?
Hi, I am having issues with my code:
Code:
on (release) {
_root.gotoAndPlay("styxgood1");
}
on (release) {
exp = + 10;
this. mymc. Styxexp = +10 ;
}
The problem I'm having is that 10 points are being added to my variable inside my movie clip, but when I click on the button again, the points do not increase. When I go to a new frame, the points completely reset. I'm trying to add points to a variable inside my movieclip titled mymc. Does anyone know how to do this? Or know what's wrong with my code?
-
.
Hi,
You have two on release and some spacings, so maybe something lie so.
PHP Code:
on (release) {
_root.gotoAndPlay("styxgood1");
exp += 10;
_root.mymc.Styxexp += 10 ;
}
-
Hi, thank you for responding. The code sadly didn't work. It did add 10 points to my variable but instead of the number becoming 20 it became 1010.
And the variable also still reset itself......
-
1> If you are getting 1010 you var is set wrong.
You will have
You want
The "" means it processes the var as a string so you are asking it to add 10 to the string ie 10+10=1010, without the "" it becomes a math problem 10+10=20
2> Your Actions Frame want to be at the highest level and spam the few length ie
My example shows the timeline
_root level
actions - F1 -> F10
Movieclip - F3 -> F4
Our Root level spans 10 frames in this instance, the actions covers all 10. You want to cover all your frames with the action line.
If you go to a frame without the var on it, when it next goes to a frame with it, will reset.
3> Try to avoid buttons, you want your code at the highest level possible to avoid issues, and make decoding easier.
You can use a movieclip as a button, and the following code on the _root timeline actions.
Code:
myButton.onPress = function(){
gotoAndPlay("styxgood1");
exp += 10;
mymc.Styxexp += 10 ;
}
Out of interest why do you have 2 exp vars in 2 different places?
This is a image from one of my project to show you what I mean by the actions covering all.
fk1x.png
Trust my code, and not my english.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|