View Full Version : Scoring
mitchinator1
07-27-2005, 04:33 PM
firstly, i searched the furoms, and i didn't find anything about this, although i may have not done a good search.
so basically, i want to know how to make the press of a button for example, add one to a dynamic text. please don't just give me the code, as this is not going in any games i'm working on, i'm just trying to learn some basic action script. so, if you have the code, but can't explain it, don't bother posting the code, it really won't help me.
arkhan
07-27-2005, 06:22 PM
on(release){
_root.score++
}
its simple..when you press the buttom, it adds one to the variable score located on the _root...
++ adds one to the variable(if its a number)
..this code would go inside the buttom..
then you have a dynamic textbox on the screen, refering to the variable _root.score(or just score if the textbox is on the stage)
mitchinator1
07-28-2005, 08:34 AM
ok thanks a lot..now, how would i make it add, say 5? would it be ++5? or +5?
ok your code didn't work.. are you sure your codes right?
on(release){
_root.score++
}
to me, it looks like the instance name there would be score++, but the instance name is just score, so how would it add anything?
arkhan
07-28-2005, 10:18 AM
to add 5, you type +=5..
score+=5
is the same as
score=score+5
theres no instace name...you dont have to name anything here...you just have to reffer the textbox to the variable score..
_root.score is the absolute path where the variable is stored..its also a good idea to have it declared before trying to add anything to a non existant variable..
all you have to do is add the line
score=0
on the frame actions
That wouldnt work arkhan... hes using a dynamic text...
If you use _root.score+=5
it will add that number to the end of the string... I suggest using another variable to assign the score to and then after you increment it by 5 then make the text variable equal the score holder...
or use
_root.score++;
_root.score++;
_root.score++;
_root.score++;
_root.score++;
Insane Knux
07-28-2005, 12:42 PM
Or for example...
bulletHitEnemy = Function(){
if(bullet.hitTest(_root.enemy){
_root.score++;
_root.score++;
_root.score++;
_root.score++;
_root.score++;
}
}
Probably not the exact code but something close...
So you could call that function so you won't have to make pretty code look really unorganized, lol.
arkhan
07-28-2005, 12:42 PM
-.-
if the variable is a number, it will add 5 to the number..unless you assigned it as a string..witch is not what I said..doesnt matter if you are showing its value in a textbox..
-----------
Or for example...
Code:
bulletHitEnemy = Function()
bulletHitEnemy = Function()
if(bullet.hitTest(_root.enemy){
_root.score++;
_root.score++;
_root.score++;
_root.score++;
_root.score++;
}
Probably not the exact code but something close...
now THAT..O.O...thats just wrong..
That code doesnt even implement the function... And if your using a function wouldnt it go into the hitTest if statement... Just use 2 variables...
name your text displayscore
and your score variable score
then you can just go
_root.score+=5;
_root.displayscore=_root.score;
simple as dat
Insane Knux
07-28-2005, 01:10 PM
I would've tested it but Flash MX 2004 is being a bi-Otch and it's harder for me to write AS outside of FMX2004.
arkhan
07-28-2005, 01:59 PM
g3ko..man..what you said makes no sense...about the function..
and to show a vriable in a textbox, thats not necessary..you can go on properties and make the dynamix textbox show the value of score..
but if you still want to show it with AS, you must change the property text in the textbox instance..that is
path.instance.text=whatever
in the case of whta you said
_root.displayscore.text=_root.score
But if the textbox is assigned to the variable directly it thinks its a string and then when I use +=5 it just adds a 5 to the end.
0
05
055
0555
I suppose a simple var declaring could fix this?
arkhan
07-28-2005, 02:51 PM
yeah..if you dont declare the variable it will have the value "undefined"...and if you add 5 to it, its just no good..
also, declaring
score="0"
makes it a string..and adding +="5" same...
you gotta declare it as a number in any case if you want it to be a number..
yup. I just always found it easier to have 2 variables. So this would work?:
var _root.score:Number=0 as a declaration and then
_root.score+=5
mitchinator1
07-29-2005, 11:21 AM
so can some one tell me the full code? one that works?..i'm just trying to leanr how to make one event, change another basically..
Just put this into a mc in the onClipEvent(load) handler:
_root.score=0;
And put these where ever the scoring occurs:
_root.score+= [whatever you want to higher the score by] ;
_root.displayscore=_root.score;
Just name a dynamic text box variable : displayscore
Make sure its in the main timeline...
Lol. I did it again I just prefer having two variables :/
arkhan
07-29-2005, 05:12 PM
we went through this already..you can make the text box show the variable score..it wont affect its type..
Loyaltom
07-30-2005, 04:58 AM
keeping score in flash
By: Zak
1.) Make a large circular button, highlight the entire button and press F8 (convert to symbol) after that is completed you change the default selected to button instead of movie clip. Then click OK.
2.) Make a smaller button and again highlight the entire button, press F8 (convert to symbol) and then select button instead of movie clip, then press OK.
3.) Select the text tool and make a text that say 'score'.
4.) Select the text tool again and then make another text box right after that, but look at the bottom under properties and change it from "static text" to "dynamic text." Also in the bottom make the variable total.
5.) Now back to our circle buttons, right click on the big one and copy and the paste the following code into the the actions box.
Code:
on (release) {
_root.total = _root.total + 100;
}
6.) now right click on the little button and go to actions and again copy and past the following code into the actions box.
Code:
on (release) {
_root.total = _root.total - 100;
}
7.) Now you can run the "animation" and see your results in the variable box where you made that 'static text' into 'dynamic text'
HINT: Where it says + 100 and - 100 you can change these to like + 200 and - 200 or whatever you please
I can... but I wont and you cant make me... then you do it :/ ive already explained it too many times :/
The Brown Cow
07-30-2005, 12:39 PM
Never, ever use a dynamic text field to store a value. Make a variable in your movie, and have the text field display that value. Otherwise, you'll have to deal with the whole string vs number issue and the fact that if your text field is not onscreen, you no longer can use that value.
Thank you, TBC. Thats the point I'm trying to make... its just so much easier to avoid that all together.
arkhan
07-31-2005, 12:20 PM
g3ko..tbc said you shouldnt use text fileds to store values...but if you have a variable, and the text field showing the value of the variable, then its ok..
vBulletin® v3.7.3, Copyright ©2000-2010, Jelsoft Enterprises Ltd.