Forum Topic: AS: Varables more

(1,524 views • 20 replies)

This topic is 1 page long.

<< < > >>
None

phyconinja

Reply To Post Reply & Quote

Posted at: 6/27/06 07:42 AM

phyconinja EVIL LEVEL 25

Sign-Up: 09/18/04

Posts: 2,825

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

None

Fion

Reply To Post Reply & Quote

Posted at: 6/27/06 07:56 AM

Fion LIGHT LEVEL 34

Sign-Up: 08/21/05

Posts: 2,375

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

None

phyconinja

Reply To Post Reply & Quote

Posted at: 6/27/06 08:01 AM

phyconinja EVIL LEVEL 25

Sign-Up: 09/18/04

Posts: 2,825

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..


None

Paranoia

Reply To Post Reply & Quote

Posted at: 6/27/06 08:38 AM

Paranoia DARK LEVEL 34

Sign-Up: 04/22/05

Posts: 9,697

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

None

phyconinja

Reply To Post Reply & Quote

Posted at: 6/27/06 08:56 AM

phyconinja EVIL LEVEL 25

Sign-Up: 09/18/04

Posts: 2,825

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..


None

Fion

Reply To Post Reply & Quote

Posted at: 6/27/06 09:01 AM

Fion LIGHT LEVEL 34

Sign-Up: 08/21/05

Posts: 2,375

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


None

liaaaam

Reply To Post Reply & Quote

Posted at: 6/27/06 09:22 AM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,546

Also, you need to know that:

"3" !== 3 = true

Yet

"3" != 3 = false


None

Paranoia

Reply To Post Reply & Quote

Posted at: 6/27/06 09:43 AM

Paranoia DARK LEVEL 34

Sign-Up: 04/22/05

Posts: 9,697

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

None

PBM

Reply To Post Reply & Quote

Posted at: 6/27/06 10:16 AM

PBM NEUTRAL LEVEL 21

Sign-Up: 03/24/00

Posts: 646

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


None

phyconinja

Reply To Post Reply & Quote

Posted at: 6/27/06 10:20 AM

phyconinja EVIL LEVEL 25

Sign-Up: 09/18/04

Posts: 2,825

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!!!
; )


None

SpamBurger

Reply To Post Reply & Quote

Posted at: 6/27/06 10:21 AM

SpamBurger NEUTRAL LEVEL 15

Sign-Up: 07/12/05

Posts: 4,747

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.

"However, the game received only two orders, one of which Molyneux speculated was from his mother." -Peter Molyneux's first game The Entrepreneur


None

PBM

Reply To Post Reply & Quote

Posted at: 6/27/06 10:23 AM

PBM NEUTRAL LEVEL 21

Sign-Up: 03/24/00

Posts: 646

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.


None

phyconinja

Reply To Post Reply & Quote

Posted at: 6/27/06 10:40 AM

phyconinja EVIL LEVEL 25

Sign-Up: 09/18/04

Posts: 2,825

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??


None

authorblues

Reply To Post Reply & Quote

Posted at: 6/27/06 11:17 AM

authorblues FAB LEVEL 12

Sign-Up: 06/21/05

Posts: 6,360

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.

GENERATION 1-i: The first time you see this, copy it into your sig on any forum. Square it, and then add i to the generation.

BBS Signature

None

phyconinja

Reply To Post Reply & Quote

Posted at: 6/27/06 11:34 AM

phyconinja EVIL LEVEL 25

Sign-Up: 09/18/04

Posts: 2,825

you lurn somthing every day!!
=D


None

phyconinja

Reply To Post Reply & Quote

Posted at: 6/29/06 09:50 AM

phyconinja EVIL LEVEL 25

Sign-Up: 09/18/04

Posts: 2,825

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!!


None

authorblues

Reply To Post Reply & Quote

Posted at: 6/29/06 10:03 AM

authorblues FAB LEVEL 12

Sign-Up: 06/21/05

Posts: 6,360

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

GENERATION 1-i: The first time you see this, copy it into your sig on any forum. Square it, and then add i to the generation.

BBS Signature

None

Paranoia

Reply To Post Reply & Quote

Posted at: 6/29/06 10:06 AM

Paranoia DARK LEVEL 34

Sign-Up: 04/22/05

Posts: 9,697

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

None

authorblues

Reply To Post Reply & Quote

Posted at: 6/29/06 10:07 AM

authorblues FAB LEVEL 12

Sign-Up: 06/21/05

Posts: 6,360

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.

GENERATION 1-i: The first time you see this, copy it into your sig on any forum. Square it, and then add i to the generation.

BBS Signature

None

andrease

Reply To Post Reply & Quote

Posted at: 3/26/07 05:06 PM

andrease FAB LEVEL 11

Sign-Up: 11/01/02

Posts: 670

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!


None

Snubby

Reply To Post Reply & Quote

Posted at: 3/26/07 06:27 PM

Snubby EVIL LEVEL 20

Sign-Up: 12/04/04

Posts: 3,149

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.


All times are Eastern Standard Time (GMT -5) | Current Time: 12:45 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!