00:00
00:00

AS: Varables more

2,705 Views | 19 Replies
New Topic Respond to this Topic

AS: Varables more 2006-06-27 07:42:22


AS: Main.. my playground

this is not a new AS: variable that I want to replace the "old" one.. but if you want to know more, this is the place..

you should read this first..
AS: Variables by Rantzien

ok, in the other AS: Variable you lurned how to declare variables.. but not how to read them..
there is diferent ways..

if:

lets say you want somthing to hapend if "number" =5..
then you have to use this code

if (number == 5){
//code here
}

one of the most comon errors I see here is people only have one "="
(number=5)
if you only have one "=" you sett the variable to 5
you need two "==" to check it..
you can also check if the information in the variable is corect..
if (name == "phyconinja"){
//code here
}

remember to have the " " there.. else it wont read it as information and try to use it as another variable..

you can also use < or >..

if (number>5){
//code here
}

checks if numer is bigger then 5

textbox
if you want the people who plays the game to see what the variable is, lets say its the health of the player.. you create a Dynamic textbox, and click on it.. you will see in the properties panel that ther is a part that says "var" that is the variable that the box will read.. make shure it is a time line variable
_root.health

Changing variables

another thing that didnt show in the last one was chaging the variable..
lets say you have a variable called "health" and you want it to go down by 10 points if "enemy" hits you..
read: AS Collision by Glaiel_Gamer
(hitTest)

if (this.hitTest(_root.enemy)){
health-=10;
}

health-=10; is the same as health = health -10;

you can have :
-= (number=number-"somthing")
+= (number=number+"somthing")
++ (number=number+1)
-- (number=number-1)

other useful tuts:
AS: Random by -Reedo11-
AS: Math by T-H AS: Arrays by Denvish
AS: Arrays by Creeepy

PS. I'm Norwegian, so my use of English may be bad...

lol
XD

Response to AS: Varables more 2006-06-27 07:56:07


Beautiful, I have recently read the variable tutorial by Rantzien and was thinking it was missing a few components. You have summed up a few extra point very well and hopefully this will keep people from asking the same old questions.

Your English is well done too

.

BBS Signature

Response to AS: Varables more 2006-06-27 08:01:14


At 6/27/06 07:56 AM, Fionmaster wrote: Beautiful, I have recently read the variable tutorial by Rantzien and was thinking it was missing a few components. You have summed up a few extra point very well and hopefully this will keep people from asking the same old questions.

thanks..
I noticed that alot of people was asking questions about variables.. so I read the AS: Variables, and I thougt it was missing somthing to. so I desided to make this..

Response to AS: Varables more 2006-06-27 08:38:45


At 6/27/06 07:42 AM, phyconinja wrote: you can have :
-= (number=number-"somthing")
+= (number=number+"somthing")
++ (number=number+1)
-- (number=number-1)

You're forgetting the other assignments:

vari *= 2 // returns vari as its previous value multiplied 2
vari /= 2 // returns vari as its previous value devided by 2
vari %= 2 // returns vari as its remainder when divided by 2 - particularly useful if you want a variable to go to a certain number then reset.

May as well do multiple declerations too:

var vX:Number = _root._xmouse;
_x = vX

Can be shortened to:

var vX:Number = _x = _root._xmouse;

Also, you could have put a more detailed description of the use of variables in conditions. a condition checks if something is true or false, so while:

good = true;
if(good == true){
}

Will return true and execute the code, because good being equal to true is true, you may as well have:

if(good){
}

Becuase the value is returning true anyway. Similarly, instead of having:

if(good == false){
}

You can just put:

if(!good{
}

From a binary point of view, it's also worth remembering that any non-zero and non-NaN or undefined number returns as true in these conditions (I think :P), so:

good = 5;
if(good){
}

Should also work.

Don't quote me on that last bit, though :P


BBS Signature

Response to AS: Varables more 2006-06-27 08:56:09


At 6/27/06 08:38 AM, _Paranoia_ wrote: You're forgetting the other assignments:
vari *= 2 // returns vari as its previous value multiplied 2
vari /= 2 // returns vari as its previous value devided by 2
vari %= 2 // returns vari as its remainder when divided by 2

holy shitt..
how could I forget that?!?
sorry..

Response to AS: Varables more 2006-06-27 09:01:15


Well there are heaps more assignments than that to isnt there?


.

BBS Signature

Response to AS: Varables more 2006-06-27 09:22:11


Also, you need to know that:

"3" !== 3 = true

Yet

"3" != 3 = false


Sup, bitches :)

BBS Signature

Response to AS: Varables more 2006-06-27 09:43:41


At 6/27/06 09:01 AM, Fionmaster wrote: Well there are heaps more assignments than that to isnt there?

There are bitwise assignments and stuff, but they're a bit more complicated.


BBS Signature

Response to AS: Varables more 2006-06-27 10:16:20


Very good Phyco. I actually understood it all :)
Then along came Paranoia and my brain exploded...then Liammm and my brain imploded. Thanks guys!!

Response to AS: Varables more 2006-06-27 10:20:05


At 6/27/06 10:16 AM, PBM wrote: Very good Phyco. I actually understood it all :)
Then along came Paranoia and my brain exploded...then Liammm and my brain imploded. Thanks guys!!

people sometimes forgets that not everyone is as good as them, and thinks the same ways as them..
LoL
I tryed to make people understand what i said.. even n00bs.. cuz this tut was ment for n00bs..

not saying that you are one!!!
; )

Response to AS: Varables more 2006-06-27 10:23:29


At 6/27/06 10:20 AM, phyconinja wrote:
At 6/27/06 10:16 AM, PBM wrote: Very good Phyco. I actually understood it all :)
Then along came Paranoia and my brain exploded...then Liammm and my brain imploded. Thanks guys!!
people sometimes forgets that not everyone is as good as them, and thinks the same ways as them..
LoL
I tryed to make people understand what i said.. even n00bs.. cuz this tut was ment for n00bs..

not saying that you are one!!!
; )

Well..when AS is concerned Im pretty n00bish. Im ok with that tho. I am trying to learn tho and taking in everything I see as far as the action scripting is concerned. Im getting better bit by bit. It will be ahile tho. Thanks for your help.

Response to AS: Varables more 2006-06-27 10:40:57


At 6/27/06 10:21 AM, SpamBurger wrote: Yea, like -liam- said, you forgot about ===. The three ='s is just a more strict way of checking. It basically checks for same value, and same datatype.

doesnt == do that to??

Response to AS: Varables more 2006-06-27 11:17:04


At 6/27/06 10:40 AM, phyconinja wrote: doesnt == do that to??

== checks for variable equality
=== checks that the variables are both equal and of the same datatype

hence why liam said that "3" == 3 would be true,
but "3" === 3 would return false.


BBS Signature

Response to AS: Varables more 2006-06-27 11:34:19


you lurn somthing every day!!
=D

Response to AS: Varables more 2006-06-29 09:50:17


At 6/27/06 08:38 AM, _Paranoia_ wrote: vari %= 2 // returns vari as its remainder when divided by 2 - particularly useful if you want a variable to go to a certain number then reset.

sorry.. I just have to ask..
what does that mean?
Iv never heard of it, and never used it..
and didnt understand your explenation!!

Response to AS: Varables more 2006-06-29 10:03:24


At 6/29/06 09:50 AM, phyconinja wrote: sorry.. I just have to ask..
what does that mean?

its called a modulus assignment. modulus returns the remainder after division.

trace(5%2); // returns 1, since 5/2 = 2r1
trace(8%2); // returns 8, since 8/2 = 4r0
trace(8%3); // returns 2, since 8/3 = 2r2
trace(10%4); // returns 4, since 10/4 = 2r2

therefore, the modulus assignment works the same way:

var n:Number = 5;
n %= 2;
trace(n); // returns 1


BBS Signature

Response to AS: Varables more 2006-06-29 10:06:33


At 6/29/06 10:03 AM, authorblues wrote: its called a modulus assignment. modulus returns the remainder after division.

It's an odd little function but it's good for quite a few things, especially if you're into coding binary.


BBS Signature

Response to AS: Varables more 2006-06-29 10:07:46


At 6/29/06 10:06 AM, _Paranoia_ wrote: It's an odd little function but it's good for quite a few things, especially if you're into coding binary.

its also good for repetitive motion engines. i use modulus quite often.


BBS Signature

Response to AS: Varables more 2007-03-26 17:06:21


Hey i got like a killer problem.. The if statements dont work in Flash 8! what do i need to type instead of :
if (health==100){
gotoAndPlay(2);
}

?


Fuck the corporate world!

Response to AS: Varables more 2007-03-26 18:27:46


At 3/26/07 05:06 PM, andrease wrote: Hey i got like a killer problem.. The if statements dont work in Flash 8! what do i need to type instead of :
if (health==100){
gotoAndPlay(2);
}

?

_root.gotoAndPlay (2);

That may be the problem if you want the main timeline to go to frame 2. Or, maybe if it's on a moveclip you need the right clip event...

onClipEvent (enterFrame)
{
...
}

Etc. Etc. The if condition does work man you can't blame Flash.