Announcement

User registrations are currently disabled due to high spam traffic.

#1 06/03/07 7:40pm

der-zef-meister
Addict
From: barrow-in-furness
Registered: 21/01/07
Posts: 267

Dudeman's Adventures

I took your advice SoulOfDarkness and made a new topic.

http://i149.photobucket.com/albums/s62/ … ntures.swf

Now there should be no problems with that!!
As for help, I'm more or less a begginer. I'm familiar with flash and animation but not action scripting. The only code i know off by heart are simple frame functions (stop(); gotoAndPlay(); etc.) and how to program buttons :-)

All but one of my interactive creations have been a result of a tutorial. The tutorial i found for Dudeman is on newgrounds.com (i also borrowed script from other tutorials and put it in). Anyhow, here is the code that goes inside the player:

Code:

onClipEvent (load) {    
moveSpeed = 10;
}
onClipEvent (enterFrame) {    
if (Key.isDown(Key.RIGHT)) {        
this._x += moveSpeed;    
} else if  (Key.isDown(Key.DOWN) && !fall) {        
this._y += 0;    } else if (Key.isDown(Key.LEFT)) {        
this._x -= moveSpeed;    
}
}
onClipEvent (enterFrame) {   
if (Key.isDown(KEY.UP) && !jumping) {        
vel_y = 36;        jumping = true;
}
if (jumping == true) {        
vel_y -= 2;       
} if (vel_y<=-15) {            
vel_y = -15;
}        
this._y -= vel_y;    
}    
if (_root.ground.hitTest(this._x, this._y+35, true)) {        
vel_y = 0;        
jumping = false;    
}
}
onClipEvent (enterFrame) {   
this._y += 16;    
if (_root.ground.hitTest(this._x, this._y+1, true)) {        
this._y -= 16;    
}
}
onClipEvent(enterFrame){
if(this.hitTest(_root.level)){
_root.gotoAndStop(3);
}
}

I have 2 other MC s on the stage, the ground (instance of ground) and the red dot (instance of level).

There are several things i would like to know.
1. syntax
2. what all of the true/false things mean
3. what things like ++, -=, <=-15 etc. mean

Last edited by soulofdarkness (06/03/07 9:04pm)


The shadow of the wicker man is rising up again...

Offline

 

#2 06/03/07 9:03pm

soulofdarkness
Moderator
From: Tallinn
Registered: 25/08/06
Posts: 401

Re: Dudeman's Adventures

Ok, first of all, I'd advie you to but the code on the forum bestween {code} and {code} (replace {} with [])
". That will make it much easier to understand for forum viewers wink. I'll do the thing for you for now.

The main thing when you learn ActionScript (AS) is not HOW to write, but WHY to write a sertain line of code.
Let's start understanding =P
In AS, everything has it's meaning, and if you understand that, it will be easy to code for you. If you want to make an explanation for yourself (like, if you're starting to code the script you haven't seen fo months), you use "//"

Code:

//everything that stays within this line will be skipped by Flash

To give a definition the the code we use "()".
Instead of a "." action script is using ";"

Code:

onClipEvent (load) {
        moveSpeed = 10;
}

onClipEvent means that the object this a MovieClip.
(load) load means that the code that's between "{" and "}" will work only once, when the MC loads.
{ Means that the actual code begins here.
moveSpeed = 10; is a variable. It is used to replace a number. Look into your script: see how often "moveSpeed" appears? If you werent using this variable, you would have to wrie "10" everywhere, and if you want to make your character move slower or faster, you would have to change the number all along.
But now, the nly number you need tho change is the one that's after "moveSpeed =". Note that you could write anything you want there. If you write "worm = 10" and change "moveSpeed" into "worm" in the whole script, it will still work.
}is showing Flash that this piece of code is over.

Now, this is what a Flash Player would "think", when it'd see the script.

Code:

This code should be on a movieclip, and work when the clip is loaded.
Now, everytime i will see "moveSpeed", i should replace it with "10".

Last edited by soulofdarkness (06/03/07 9:05pm)


I bite!
surprise

Offline

 

#3 06/03/07 9:15pm

Jake
Administrator
Registered: 29/04/06
Posts: 307

Re: Dudeman's Adventures

can help a bit true and false are used to let flash know if something is true or not eg

Code:

if (jumping){
     // code runs if jumping is true
     jumping = false; // sets jumping to false so this script wont run again until jumping is set back to true
}

You can also test to see if something is false by using an exclamation mark beforehand which stands for not eg.

Code:

if (!jumping){
     // code runs if jumping is false
}

True and false can also be used on movie clips for example the following will make the movie clip "ball" no longer visible

Code:

ball._visible = false;

As for the other things, ++ means an increment of 1 so x++ will increase the value of x by 1, similarly -- means decrease the value by 1.

-= is used when you want to subtract a number from another eg x-=3 will subtract 3 from x and is useful so you do not have to type x=x-3 which essentially means the same. Again += is used for an increment eg x+=3 will add 3 on to x.

<=-15 means less than or equal to -15 >=-15 would be greater than or equal to -15.

You can find out more about these things if you use the help in flash. Go to ActionScript 2.0 Language Reference > ActionScript language elements > Operators to find out all about operators.

Just so you don't make the common mistake, if you want to see if a value is equal to another value you have to use == as = will assign the value you are checking with to the variable you want to check.

For tutorials I find kirupa and flashkit really good. It is also usefull to know that a lot of people will write tutorials thinking that they know what they are doing and unfortunately when it comes to things like platform games then there are many poor tutorials about. You soon get a feel of what is good and bad though.


moose

Offline

 

#4 06/03/07 10:08pm

der-zef-meister
Addict
From: barrow-in-furness
Registered: 21/01/07
Posts: 267

Re: Dudeman's Adventures

Thanx people. I kinda knew most of that but it's good to have it explained. What i don't understand Jake, is what is jumping? it hasn't been set as a variable in the onClipEvent{load} bit and i can't see it anywhere else. Also, i know that every statement in flash ends with a semicolon, are there any other rules that i need to know about?


The shadow of the wicker man is rising up again...

Offline

 

#5 06/03/07 10:42pm

Jake
Administrator
Registered: 29/04/06
Posts: 307

Re: Dudeman's Adventures

what is basically happening is there is a variable "jumping" which is being used so that when it is true the player is in the air and therefore needs to have effects of gravity applied to it so it then falls back down. The variable jumping is not specific to flash the person who wrote the tutorial will have just used it to make it easier to understand the code.

As the variable "jumping" is boolean as a default it is set to "false" hence why it is not set as a variable, perhaps it should have been to make the code easier to understand.


moose

Offline

 

#6 07/03/07 12:56am

tallphil
Banned
From: UK
Registered: 29/04/06
Posts: 823
Website

Re: Dudeman's Adventures

If you've never done any coding before, it's a bit of an uphill struggle before you can really understand most code - a steep learning curve! However, once you understand the basics it all gets a lot simpler and more obvious. Before you go launching into writing games and understanding relatively complex tutorials, it'd probably be good to do a fair bit of reading and cover the basics - it'll be better in the long run as if you know your first principles code becomes less overwhelming and you're less likely to give up smile

Kirupa has some good beginner tutorials on useful stuff like using strings, if/else tests, naming conventions, using _root, _this and _parent and for/in loops (similar to if/else constructs)

Might take you an hour or so to read and digest all that stuff now, but could save you days or weeks further down the line... big_smile


By the way, boolean logic is just using true or false. Took me ages to figure that out when i was first starting out tongue


PSP Flash Gaming creator

Offline

 

#7 08/03/07 9:01pm

der-zef-meister
Addict
From: barrow-in-furness
Registered: 21/01/07
Posts: 267

Re: Dudeman's Adventures

So when you want the gravity thing to work, you say that jumping = true and somewhere in the code you have something like:

if(jumping=true){//code for gravity;}

is that how it works? i also think that there's something called binary which is similar but uses 0 and 1 instead of true and false.


The shadow of the wicker man is rising up again...

Offline

 

#8 08/03/07 9:14pm

tallphil
Banned
From: UK
Registered: 29/04/06
Posts: 823
Website

Re: Dudeman's Adventures

yup, that's right - you have to be careful that the if statement is in a section of code that will be called at the appropriate time (you can't just stick it on a stopped keyframe for example, it would only run once when you move onto that keyframe)

Binary is a teeny bit more complicated than you described there, but yeah - it can use boolean logic with 0s and 1s smile (ask woodpecker about this stuff big_smile)


PSP Flash Gaming creator

Offline

 

#9 09/03/07 1:05am

woodpecker106
Hardcore Member
From: Cardiff
Registered: 29/04/06
Posts: 109
Website

Re: Dudeman's Adventures

Did you know that there are 10 types of people, those that understand binary and those that don't.

Offline

 

#10 09/03/07 1:59pm

soulofdarkness
Moderator
From: Tallinn
Registered: 25/08/06
Posts: 401

Re: Dudeman's Adventures

smile


I bite!
surprise

Offline

 

#11 09/03/07 10:31pm

der-zef-meister
Addict
From: barrow-in-furness
Registered: 21/01/07
Posts: 267

Re: Dudeman's Adventures

man, that is knida sad but in a funny way


The shadow of the wicker man is rising up again...

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson