Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Macnoviz

macrumors 65816
Original poster
Jan 10, 2006
1,059
0
Roeselare, Belgium
Hi, I am making a little game for the youth council in my town, but the only code I have ever written before that was on a Texas instruments calculator.
I already figured out quite a bit, but I need help to make a system to keep the score.
I need a piece of code that I can use in a symbol, which adds 1 to a number in the bottom in the stage every time the symbol is pushed.
roughly it would look like:

(beginning of the scene)
0 store to "a"

(in the actions for the symbol, I already have the trigger code, I just need the effect code)
("a"+1) store to "a"

and then the ability to display "a" in a text frame on stage



I also need to have code to trigger a frame jump after a certain time period (say 30 seconds)
 

electric

macrumors regular
Oct 14, 2002
166
5
San Francisco, CA
Try this

// put your dynamic text field name below to the right of the equals sign
var textFieldName = yourTextFieldHere
// make a equal 0;
var a=0;
// give text field count of 0
textFieldName.text = a;
// function called (triggered) by what ever makes a score
function counter(){
// add new score
a++;
// give text field updated count
textFieldName.text = a;
trace(a);
}

// to trigger the score to count, call the function
counter();
 

electric

macrumors regular
Oct 14, 2002
166
5
San Francisco, CA
Paste that code into the first keyframe of a layer.

change the name of the text field "yourTextFieldHere" to match yours. make sure that your text field name is in the box to the left in properties not the box to the right(var)

trigger the score to count with counter();
 

Macnoviz

macrumors 65816
Original poster
Jan 10, 2006
1,059
0
Roeselare, Belgium
I tried it and it almost works

The only problem is that the action triggering the count is buried in a symbol that is not directly on the main timeline, and that doesn't seem to trigger the count. I tried it with a simple button in the main timeline, and there it worked beyond expectations. Could it be the a isn't a global variable? and if so, how do I need to change the code

PS I checked the help, but it got worse
 

electric

macrumors regular
Oct 14, 2002
166
5
San Francisco, CA
New code

// put your dynamic text field name below to the right of the equals sign
var textFieldName = yourTextFieldHere
// make a equal 0;
var a=0;
// give text field count of 0
textFieldName.text = a;
// function called (triggered) by what ever makes a score
_global.counter = function(){
// add new score
a++;
// give text field updated count
textFieldName.text = a;
trace(a);
}

// to trigger the score to count, call the function
counter();

-----------------------------------------------------
just replace:
function counter(){

with:
_global.counter = function(){

------------------------------------------------------
now you can call counter(); from where ever
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.