Forum Topic: AS: Variables

(4,462 views • 53 replies)

This topic is 2 pages long. [ 1 | 2 ]

<< < > >>
None

Toast

Reply To Post Reply & Quote

Posted at: 6/30/05 05:21 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,918

I have seen many people not knowing what variables are.
I think variables are very important to learn because they can be a great use.I will exaplin why you need to learn variables,how they work,and where/when you can use them.

What are variables?
The variable system has been added to flash since flash no.5.They are
usally used to ismplify scripts or to shorten codes.They are very often used with a boolean,true or false.Basicly,they can be anything you want.I sometimes type su=10; instead of speed_up=10;

How can variables be used?
They are mostly used with "onClipEvent(load){"The only difference between onClipEvent(load){ and onClipEvent(enterFrame){ is that onClipEvent(enterFrame){ performs an action every frame,meaning that if the frame rate is one,the action would be performed every frame.
They can be whatever you want as long as each variable has always got the same name.
Example:

onClipEvent(load)
{
teh_lolz = 5;
}
onClipEvent(enterFrame)
{
this._y -= teh_lolz;
}

That is a very simple code which make "this" go up by 5 pixels every frame.
Every time that "flash sees" teh_lolz.it takes it as a five.It is not hard to understand,is it?

"Why do I need to use variables?"
Sometimes,as the example I gave,you don't have to use variables.But sometimes you have to use ' em.
Example:
I want to make a RPG game,I know how to make a character move,but I want to know how to make him stop when there is a buiding.One of the choices would be to apply the same movement code but to the other direction.
Example:

onClipEvent(enterFrame)
{
this._x +=5;
if(this.hitTest(_root.rightwall))
{
this._x -=5;
}
}

But what if the speed changes during the game?In this case you have to use variables.Instead of reversin the speed,you can simply stop it with variables.
Example:


onClipEvent(load)
{
TehSpeed = 5;
}
onClipEvent(enterFrame)
{
this._x += TehSpeed;
if(this.hitTest(_root.rightwall))
{
TehSpeed=0;
}
else
{
TehSpeed=5;
}
}


I think you got the idea.The tutorial ends here. :o


None

Inglor

Reply To Post Reply & Quote

Posted at: 6/30/05 07:45 AM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

SHAME ON YOU!!!!

at least TEACH the correct syntax if you're not going to use it ;)

from AS: Debugging Syntax
Full decleration:

Whenever you make full decleration (which is importent for the compiler to identify your errors) you also specify the return type, for example

var i:Number;

declares a number variable called i

var arr:Array=new Array();

declares a new array.

var s:String="lololololol";

creates a new string variable, names it s, and puts 'lolololol' in it


None

Toast

Reply To Post Reply & Quote

Posted at: 7/23/05 09:26 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,918

At 6/30/05 07:45 AM, Inglor wrote: Shame on Inglor's mum!!!

I sometimes use it but it is not always necessary.
var lol = 5;
Are you teh happy now? >: (


None

Inglor

Reply To Post Reply & Quote

Posted at: 7/23/05 09:28 AM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

At 7/23/05 09:26 AM, -Toast- wrote: My Grandma likes it when I put it big and hard up her ass

actually, it's

var lol:Number=5;


None

Toast

Reply To Post Reply & Quote

Posted at: 7/23/05 09:30 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,918

Inglor once typed:
I'm teh 1337!!11!!11

No need for that,this is a basic variables tutorials. lol = 5; and var lol = 5; both work perefectly.


None

Inglor

Reply To Post Reply & Quote

Posted at: 7/23/05 09:32 AM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

At 7/23/05 09:30 AM, -Toast- wrote: I touch myself when I look at Denvish's or liam's posts
No need for that,this is a basic variables tutorials. lol = 5; and var lol = 5; both work perefectly.

well, I did state it's advantage for debugging, and for correct syntax, AS 3 does NOT let you just do "lol=5" and enjoy fast speed accell


None

liaaaam

Reply To Post Reply & Quote

Posted at: 7/23/05 10:02 AM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,536

At 7/23/05 09:30 AM, -Toast- wrote: I touch myself when I look at Denvish's or liam's posts

Well, erm.. thanks :)


None

Denvish

Reply To Post Reply & Quote

Posted at: 7/23/05 10:28 AM

Denvish DARK LEVEL 46

Sign-Up: 04/25/03

Posts: 16,236

At 7/23/05 10:02 AM, -liam- wrote: Donkeys arouse me

I hope you use protection

- - Flash - Music - Images - -

BBS Signature

None

Inglor

Reply To Post Reply & Quote

Posted at: 7/23/05 10:30 AM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

At 7/23/05 10:28 AM, Denvish wrote:
At 7/23/05 10:02 AM, -liam- wrote: Donkeys arouse me
I hope you use protection

fuck that made me lol hard, so hard it woke my mom up and now she is mad at me...


Happy

D-to-da-P

Reply To Post Reply & Quote

Posted at: 7/23/05 10:43 AM

D-to-da-P DARK LEVEL 08

Sign-Up: 12/23/04

Posts: 684

At 7/23/05 10:30 AM, D_to_da_P wrote: This thread is awsome haha!
WTF!... haha.

well now i understand this this so called "varey abel" shit. lol


None

Inglor

Reply To Post Reply & Quote

Posted at: 7/23/05 10:51 AM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

At 7/23/05 10:43 AM, D_to_da_P wrote: I am gay and I like old beefy truck drivers... and if you're not ok with that, it's your problam >:(

Ok Ok. noone is here to judge you... no need to get all emo

I have your brains (does not link to kevan or another zombie site)

anyhow let's get back to the topic, you didn't address access control at all... oh well


None

Mogly

Reply To Post Reply & Quote

Posted at: 7/23/05 10:55 AM

Mogly LIGHT LEVEL 25

Sign-Up: 09/05/04

Posts: 10,336

THE battle of the elite coders has begun! (well, if u minus myself and d to da ps posts that is)

~ MogTom ~ Dont fuck around with my dog. All that I can see I steal. ~
NG FFR ~ Automatic for the people.

BBS Signature

None

liaaaam

Reply To Post Reply & Quote

Posted at: 7/23/05 10:55 AM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,536

At 7/23/05 10:51 AM, Inglor wrote: I have your brains (does not link to kevan or another zombie site)

No wonder yours is so high O_o

You bloody.. crackpot.


None

D-to-da-P

Reply To Post Reply & Quote

Posted at: 7/23/05 11:00 AM

D-to-da-P DARK LEVEL 08

Sign-Up: 12/23/04

Posts: 684

At 7/23/05 10:51 AM, Inglor wrote: Testicles..... is fur lunch.

just a quick question to u guys with the AS awsomeness.

do you guys memorize all the codes by now or do you have to still find them in the list and select them time to time.

to me i find it amazing to know all the code stuff, im still a n00b at AS.


None

Inglor

Reply To Post Reply & Quote

Posted at: 7/23/05 11:02 AM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

At 7/23/05 11:00 AM, D_to_da_P wrote:
do you guys memorize all the codes by now or do you have to still find them in the list and select them time to time.

we don't memorize the codes, we remmember the commands themselves and rethink the codes...


Shouting

D-to-da-P

Reply To Post Reply & Quote

Posted at: 7/23/05 11:05 AM

D-to-da-P DARK LEVEL 08

Sign-Up: 12/23/04

Posts: 684

At 7/23/05 11:02 AM, Inglor wrote:
we don't memorize da codes, we remmemba da commands themselves and rethink da codes...

Neat!


None

Rustygames

Reply To Post Reply & Quote

Posted at: 7/28/05 08:42 AM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,662

At 6/30/05 05:21 AM, -Toast- wrote: performs an action every frame,meaning that if the frame rate is one,the action would be performed every frame.

WTF?
You mean it will be run once every second if the frame rate is 1 fps. Because it will alwyas run every frame hence the on ENTERFRAME silly boy

- Matt, Rustyarcade.com


None

Inglor

Reply To Post Reply & Quote

Posted at: 7/28/05 08:44 AM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

this gets redone, sorry toast, but I'm redoing it... it just doesn't really explain variables...


None

Rustygames

Reply To Post Reply & Quote

Posted at: 7/28/05 08:47 AM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,662

At 7/28/05 08:44 AM, Inglor wrote: this gets redone, sorry toast, but I'm redoing it... it just doesn't really explain variables...

Come on lets not be too harsh I mean it does have some good qualities like...
ummm
It explains...
umm...
Well no it doesnt but at leats it links back to AS:MAIN...
Wait..
no.
no it doesnt

- Matt, Rustyarcade.com


None

Toast

Reply To Post Reply & Quote

Posted at: 7/28/05 08:56 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,918

At 7/28/05 08:44 AM, Inglor wrote: this gets redone, sorry toast, but I'm redoing it... it just doesn't really explain variables...

It doesn't mean that you have to ruin this thread : (


None

Rantzien

Reply To Post Reply & Quote

Posted at: 7/28/05 08:58 AM

Rantzien FAB LEVEL 15

Sign-Up: 01/27/05

Posts: 3,426

At 7/28/05 08:47 AM, Ninja-Chicken wrote: Come on lets not be too harsh I mean it does have some good qualities like...
ummm
It explains...
umm...
Well no it doesnt but at leats it links back to AS:MAIN...
Wait..
no.
no it doesnt

Lol. Touché.

BBS Signature

None

liaaaam

Reply To Post Reply & Quote

Posted at: 7/28/05 09:07 AM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,536

The thread shows how to use basic variables, but thats kinda it.. Inglor you wanna do it because you're an AS topic-whore ;p


None

Inglor

Reply To Post Reply & Quote

Posted at: 7/28/05 09:12 AM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

no this thread simply does not cover:

Attributes/Properties
Constants
Variable Types
What Variables are For
Advantages of certein types over the others
Global Variables, Local Variables, how to access a variable in a movieclip from outside of it (this/_parent/super)

And many more...


None

Toast

Reply To Post Reply & Quote

Posted at: 7/28/05 09:19 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,918

At 7/28/05 09:12 AM, Inglor wrote: no this thread simply does not cover:
blah blah blah
And many more...

It's a BASIC bariable tutorial.
It covers what you need to know for a simple platformer or whatever.

It covers:
Introduction.

blah blah bvlah

What they are.

What are variables?
blah blah blah

How to use them.

How can variables be used?
blah blah blah
Example:

code


blah blah blah

and what you need them for.

"Why do I need to use variables?"
blah blah blah
Example:

code


blah blah blah


blah blah blah...

I think it's enough for a basic tutorial...


None

liaaaam

Reply To Post Reply & Quote

Posted at: 7/28/05 09:22 AM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,536

At 7/28/05 09:12 AM, Inglor wrote: stuff

I agree, we do need a better variable tutorial. I want to know how to use super too, I've never used that.

You're probably the best for the job too :P


None

Inglor

Reply To Post Reply & Quote

Posted at: 7/28/05 09:23 AM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

At 7/28/05 09:19 AM, -Toast- wrote: It covers what you need to know for a simple platformer or whatever.

no it does not, you didn't once say variables are used to store data :P you said some mumbo jumbo about their usage... just because it's simple doesn't mean it has to be bad.


None

Toast

Reply To Post Reply & Quote

Posted at: 7/28/05 09:25 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,918

At 7/28/05 09:23 AM, Inglor wrote: mambo jambo?

I agree,of course, I don't have any problem if you make a new AS: Variables.
Just call it "AS: Inglor's Variables" please :P

Of course a platformer can be done with a simple knowledge of variables. I once made a platformer with my Variables knowledge : / ...


None

Inglor

Reply To Post Reply & Quote

Posted at: 7/28/05 09:29 AM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

At 7/28/05 09:25 AM, -Toast- wrote: I like to stick fingers up my ass! it's fun, my whole family does it

No thanks.

Of course a platformer can be done with a simple knowledge of variables. I once made a platformer with my Variables knowledge : / ...

Is it as good as your battle engine? let me guess... it's in pakistan? on a carpet?

Dude, you didn't explain anything in this tutorial no offense but after reading it twice I'm kinda confused about them myself :P


Angry

Toast

Reply To Post Reply & Quote

Posted at: 7/28/05 09:31 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,918

O

You should be ashamed of talking about my family like that!

BLOCKED!


None

Inglor

Reply To Post Reply & Quote

Posted at: 7/28/05 09:36 AM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

At 7/28/05 09:31 AM, -Toast- wrote:
O
I told you not to tell anyone you son of a bitch! it's a family secret!
It's not my fault... I'll just go ride my magic Alladin carpet in pakistan now >:(
You should be ashamed of talking about my family like that!

BLOCKED!

No need to get all emo again :P you're acting like I care :P


All times are Eastern Standard Time (GMT -5) | Current Time: 01:40 AM

<< Back

This topic is 2 pages long. [ 1 | 2 ]

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