I have genuinely, genuinely looked ALL over the web for a basic scoring system and can’t find one that actually works. Maybe it’s just me/ my game but nothing works.
I’m trying to do it with a dynamic text box. So i’ve got a starting score.
But when i put: “Score = Score + 10;”
Nothing happens. So yeah, any help please. I’m gonna put up most of the game code, to see if it’s something else, and there’s only ~ 30 lines…I want it so when the two objects collide the score goes up. THANKS
Oh and I embedded the text, after flash told me to. Hence the first line ↓.
import flash.text.*;
import flash.display.*;
import flash.events.*;
import flash.ui.Keyboard;
import flash.text.TextField;
var pressedKeys:Object = {};
// BASIC KEYBOARD MOVEMENT - Took it out as it is almost defs irrelevant.
var Score = 10
var myText:TextField = new TextField();
addChild(myText);
myText.text = ("Score:"+ Score);
myText.textColor = 0xFF0000;
myText.border = true;
myText.height = 20;
myText.x = 4;
myText.y = 4;
addEventListener(Event.ENTER_FRAME, hitTest)
function hitTest(e:Event):void
{
if(Hero_Mc.hitTestObject(Enemy_mc)&& (Enemy_mc.width<Hero_Mc.width))
{
Hero_Mc.width=Hero_Mc.width +4;
Hero_Mc.height=Hero_Mc.height +4;
Enemy_mc.stop();
removeChild(Enemy_mc);
addChild(Enemy_mc);
Enemy_mc.x= Math.floor(Math.random()*500);
Enemy_mc.y= Math.floor(Math.random()*350);
Score = Score + 10;
}
}
Nothing changes because
myText.textonly receives the value ofScore, not the actual reference. You can either useBindingUtils. Or, you can change the following line:to
Also, I agree with citizen. ActionScript convention is to use lowercase variables and
_prefixedfor private vars.