all groups > flash actionscript > april 2005 >
You're in the

flash actionscript

group:

Problem with numbers and .value


Problem with numbers and .value lookche
4/16/2005 12:00:00 AM
flash actionscript:
Hi,
I'm making a game and it has a scoring system (as all games should ;)) and
i'm having a problem with the system. I have the following code on a movie
clip:
onClipEvent (enterFrame) {
if (hitTest(_root.character) == true) {
_root.score += 10;
}
}
and in the frame i have:
score.value = 0;

If i use just score = 0; it works but that doesn't actually keep the score
around the movie, it only keeps it for 1 frame. But when i do the score.value
command it keeps it around the movie, but instead of adding to the score like
10, 20 etc. it ads by going 0, 010, 01010 etc.
Does anyone have any ideas, if they do thank you so much :D
Lucas
Re: Problem with numbers and .value tralfaz
4/16/2005 8:16:14 PM
[quoted text, click to view]

'value' is part of the variable's name in the code you showed but you
left it out in the clipevent code..
onClipEvent (enterFrame) {
if (hitTest(_root.character) == true) {
_root.score.value += 10;
}
}

You probably don't need the 'value' part of the variable unless there
are more parts to the score object like score.name, score.date etc.
If it's just score alone that you are using, just take out the 'value'
part.
tralfaz

Re: Problem with numbers and .value tralfaz
4/16/2005 9:32:30 PM
[quoted text, click to view]

value isn't a command, just another word that you made part of your
object.
Did you create your object like this..?

score = new Object();

Then you can add dot names to it..
score.value = 10;
score.name = "somebody";
score.day = "Weds";

onClipEvent (enterFrame) {
_root.score.value += 10;
_root.score.name = "somebody else";
// inside movieclips, use _root with the name score.value
}

tralfaz



Re: Problem with numbers and .value tralfaz
4/16/2005 10:16:13 PM
[quoted text, click to view]

You can use _global but I never do.. I just tell Flash that the
variable I want to refer to is on the _root of _level0
Example.. If your main swf file has a timeline variable called score..

// main timeline code.. This variable is directly assessable
// by any code on the main timeline
score = 0; // initialized to zero to start

// If you write code somewhere else besides the main
// timeline, then you have to refer to the variable with
// _root or _level0 or _parent
onClipEvent (enterFrame) {
_root.score += 10;
}

// From another movie loaded into another level..
_level0.score += 10;

tralfaz

Re: Problem with numbers and .value lookche
4/17/2005 12:00:00 AM
Thanks for that, i have the global thing working, but i still have the problem
with the adding of the numbers to the text (it goes 10, 1010, 101010 instead of
10, 20, 30 etc.). I uploaded an fla file to
http://www.geocities.com/lookches_new_account/rpg.fla if you want to see what
i'm using. Feel free just to mod the file and send it back to me, you dont
have to go into a huge explanation of what's going on.
Thanks!
Re: Problem with numbers and .value lookche
4/17/2005 12:00:00 AM
Thanks for that, i have the global thing working, but i still have the problem
with the adding of the numbers to the text (it goes 10, 1010, 101010 instead of
10, 20, 30 etc.). I uploaded an fla file to
http://www.geocities.com/lookches_new_account/rpg.fla if you want to see what
i'm using. Feel free just to mod the file and send it back to me, you dont
have to go into a huge explanation of what's going on.
Thanks!
Re: Problem with numbers and .value lookche
4/17/2005 12:00:00 AM
Originally posted by: Newsgroup User

Hopefully someone else can look at your fla file. I can't open MX2004
files.. just MX.

Don't worry, i made a MX version! :P
http://www.geocities.com/lookches_new_account/rpgmx.fla
I'm not using them with quotation marks, i just have the score = 0; and lives
= 5;, if you cant look at the file for any reason.
Thanks!


Re: Problem with numbers and .value lookche
4/17/2005 12:00:00 AM
I remember i got the value command from the Flash help files in MX 2004, but i
tried to find it and i couldn't. Either way, i have another textbox (var name
lives) and i have the value command being used in that, and it keeps it in the
entrie movie (but i'm only adding and subtracting values of 1, so it wont work
for the score). So then is there anyway to make the score a global variable so
the whole movie can use it?
Thanks!
Re: Problem with numbers and .value lookche
4/17/2005 12:00:00 AM
But the only reason i use the value command is so it keeps the information
stored in the memory. If i drop the value command whenever it goes to a
different keyframe it will lose the persons score. So without the value
command it wont do what i want it to do.
Is there any alternative to the value command?
Re: Problem with numbers and .value tralfaz
4/17/2005 12:05:43 AM
[quoted text, click to view]

It is probably something to do with strings versus numbers. If you
have quotes around a number, it isn't a number, it's a string, so if
you add "10" to a variable, you are adding the letters 1 and 0 not the
number 10 (no quotes).

Hopefully someone else can look at your fla file. I can't open MX2004
files.. just MX.
sorry
tralfaz

Re: Problem with numbers and .value tralfaz
4/17/2005 11:02:47 PM
[quoted text, click to view]

Ok.. I made a few changes for ya..
http://members.cox.net/4my5cats/rpgmx2.zip
tralfaz

Re: Problem with numbers and global variables lookche
4/18/2005 12:00:00 AM
YOU ARE GOD!
Re: Problem with numbers and .value Byron Canfield
4/18/2005 11:08:59 AM
Sounds to me like you are simultaneously displaying that variable in a
textfield, which, by definition, makes it of the data type String, such that
using the + operator performs concatenation rather than addition. Keep a
separate variable for your mathematical operations -- otherwise, you must
convert the value to a number every time you want to add to its value.

--
--------
Reality will not be altered to comply with preconceived notions.

Byron "Barn" Canfield
Flash example files: http://www.canfieldstudios.com

AddThis Social Bookmark Button