Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 02-08-2008, 12:54 AM   #1
been_1990
Member
 
Join Date: Jan 2008
Posts: 66
Default add score to a game

how can I add score to my game, something like this?

var score = 0;

if (bonus.hitTest(player)){
score = score+1;
trace(score);
}

Using the above code on frame 1 of the main timeline does not appear to be working Any ideas why?

And how could I send that to a output texfield?
been_1990 is offline   Reply With Quote
Old 02-08-2008, 01:02 AM   #2
Maximohoundoom
Máximo & Houndoom
 
Join Date: Feb 2008
Location: Canaries, Spain
Posts: 42
Default

The code you have there just runs once and stops, it doesn't keep on checking for the hitTest. In order to make it repeat you can use the onEnterFrame event. In order to send it to an output textbox you'll have to create a dynamic textbox on the stage and use its instance name.
ActionScript Code:
var score = 0; _level0.onEnterFrame = function(){    if (bonus.hitTest(player)){       score = score+1;       trace(score);       textbox.text = score;    } }
Maximohoundoom is offline   Reply With Quote
Old 02-08-2008, 03:23 PM   #3
been_1990
Member
 
Join Date: Jan 2008
Posts: 66
Default

It didn´t work.
What is this _level0?
my MCs are not all on the same layer , does that make a difference?
been_1990 is offline   Reply With Quote
Old 02-08-2008, 03:56 PM   #4
Maximohoundoom
Máximo & Houndoom
 
Join Date: Feb 2008
Location: Canaries, Spain
Posts: 42
Default

_level0 is the top level, the main timeline. You'll have to put the full path of the MovieClip object for it to work, if not your program will assume you are referring to a movieclip in the same leel as the script. You do that by putting the names of the movieclips they are in. For example:
if "bonus" is inside a clip named "clip1", you can refer to it with _level0.clip1.bonus.
Maximohoundoom is offline   Reply With Quote
Old 02-09-2008, 11:28 PM   #5
been_1990
Member
 
Join Date: Jan 2008
Posts: 66
Default

okay, thats right.Now how can I write this:
if (seed or seed2 or seed3 or seed4.hitTest(active_mc){// ??????
//something here...
}
been_1990 is offline   Reply With Quote
Old 02-10-2008, 12:10 AM   #6
Maximohoundoom
Máximo & Houndoom
 
Join Date: Feb 2008
Location: Canaries, Spain
Posts: 42
Default

you'd hve to do each hitTest on each object:
ActionScript Code:
if(seed.hitTest(active_mc) || seed2.hitTest(active_mc) || seed3.hitTest(active_mc) || seed4.hitTest(active_mc)){ // }
there is a batter way of doing this by applying a for loop using ["seed"+i] as the variable name.(You'll have give "seed" the name "seed1" so that you can follow a sequence).
ActionScript Code:
var bool:Boolean = false; for(var i:Number = 1;i<5;i++){    if(["seed"+i].hitTest(active_mc)){       bool = true;       break;    } } if(bool){    //Code }
This last method may be more complicated, but it will work for an unlimited ammount of movieclips named "seed"+N.
Maximohoundoom is offline   Reply With Quote
Old 02-10-2008, 07:28 PM   #7
been_1990
Member
 
Join Date: Jan 2008
Posts: 66
Default

Thank you! All working now!
been_1990 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[AS3] submit score for offline game Billy T Gaming and Game Development 5 01-30-2008 11:39 AM
Help with game - adding score on hitTest kovy999 Gaming and Game Development 4 12-20-2007 11:32 AM
FlashGameLicense.com - virtual marketplace to connect game developers and buyers AdamSchroeder General Chat 0 12-18-2007 09:16 PM
Flash game with PHP/MySQL - score faking problem Danko Gaming and Game Development 0 10-10-2005 10:09 AM
keeping score based on user, game, or whole game??? goddessasw Gaming and Game Development 2 10-16-2002 02:38 AM


All times are GMT. The time now is 04:52 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.