phore_eyes
427 posts
|
i’m making a game that (obviously) has lot’s of cvariable this is the code in my first frame
var coins = 0
var lives = 0
var score = 0
var easyscore = 0
var normalscore = 0
var hardscore = 0
var absolutlytotalycrazyscore = 0
var easycomplete% = 0
var normalcomplete% = 0
var hardcomplete% = 0
var absolutlytotalycrazycomplete% = 0
var easytime = 0
var normaltime = 0
var hardtime = 0
var absolutlytotalycrazytime = 0
this is the error message
Scene=Scene 1, Layer=actions, Frame=1: Line 8: ‘;’ expected
var easycomplete% = 0
any help here
|
|
|
arcaneCoder
2354 posts
|
Dont use the % sign in variable names, thats reserved as an operator.
|
|
|
phore_eyes
427 posts
|
|
|
|
JudeMaverick
8844 posts
|
That remainder thing… Why did they do that?
Without the %, is there any error?
|
|
|
WMDs
8 posts
|
Use strong syntax helps with debugging as well reduces load.
var coin:Number = 0;
EDIT: Oh yeah Flash dosnt use _root and globel anymore it has private and public scope
(dammm you !!!!)
|
|
|
JudeMaverick
8844 posts
|
Why are they local variables? You must have learnt it from evil jmtb02’s Flashwiki.net
There is no need to use var as long it’s in the frame.
|
|
|
phore_eyes
427 posts
|
thanks
also lets say i wanted to make variable score = variable time x variable score
what would the code be??
and would it work wth addition and subtraction??
thanks
|
|
|
arcaneCoder
2354 posts
|
EDIT: Oh yeah Flash dosnt use _root and globel anymore it has private and public scope (dammm you !!!!)
AS2 still has that. AS3 is the one that has changed a bit. Additionally, public and private namespaces are a bit different than the “scope” you are referring to.
There is no need to use var as long it’s in the frame.
It should still be used in order to train proper practices.
|
|
|
JudeMaverick
8844 posts
|
It should still be used in order to train proper practices.
There’s no need to practice. :P It’s only used in functions.
thanks also lets say i wanted to make variable score = variable time x variable score what would the code be?? and would it work wth addition and subtraction?? thanks
score=time*score
Doesn’t sound right. Get another variable so you don’t have some random bug.
|
|
|
Mitijea
70 posts
|
If both scores are the same variable, you could just write it as :
score *= time;
|
|
|
phore_eyes
427 posts
|
would it be the same for dividing???
|
|
|
arcaneCoder
2354 posts
|
There’s no need to practice. :P It’s only used in functions.
No its not.
|
|
|
Mitijea
70 posts
|
Yes, Phore_Eyes, you can do the same with dividing. Also addition and subtraction.
Say you want to divide a number VarA in half, you’d use VarA /= 2;
If you want to add three, write VarA += 3;
Or subtract VarB, VarA -= VarB;
Note: if you just want to add 1 or subtract 1 you can use, VarA++; or VarA—; respectively.
Edit: And to clarify why you originally had an error was because you used the % symbol which is the modulo operator. You can use the % the same way as the other operators:
VarA %= 7;
VarA will contain the remainder of the original VarA after dividing it by 7. Ex) If VarA was 15, it would now be 1 (15 % 7 = 1 since 7 goes into 15 two times with a remainder of 1. It just keeps the remainder.)
|
|
|
phore_eyes
427 posts
|
|
|
|
Mitijea
70 posts
|
That remainder thing… Why did they do that?
Not sure if this is what you are asking, Jude Maverick, but if you are wondering what use % could be, a practical example might be:
Say you want something to happen once every fifteen frames, then you can easily do this with % by writing inside an onEnterFrame function:
FramesSinceStart++;
if (!(FramesSinceStart % 15)) {
// Something Happens
}
|
|
|
JudeMaverick
8844 posts
|
No its not.
Really? Lollerz, I was wrong then :P
I know the function for %. It gives you the remainder.
|
|
|
pel6413
74 posts
|
% is the modulo operator, as jude said it returns the remainder.
so 20%7==6
|
|
|
2DArray
112 posts
|
Haha, using var when it’s not necessary is really just extra filesize in my opinion. Granted, it’s obviously not going to make any legitimate difference, but there’s really no need to “practice best practices” in cases when they don’t apply. Just another one of those old school opinions of mine.
|
|
|
Janck
253 posts
|
Granted, it’s obviously not going to make any legitimate difference, but there’s really no need to “practice best practices” in cases when they don’t apply. Just another one of those old school opinions of mine.
‘Greater interpretation and compiling speed’ + ‘preparing you for other languages like C that are bitchy about that sort of thing’ are always good.
|