February 09, 2012, 05:28:26 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Prowlie Welcome back! The site migration is complete and normal service resumed.
Advanced search
Pages: [1]   Go Down
Print
Author Topic: Basic Action Script help  (Read 1013 times)
0 Members and 1 Guest are viewing this topic.
Rade
Heroic
******
Offline Offline

Gender: Male
Posts: 3427



« on: November 19, 2009, 02:37:22 PM »

Where should I begin. I was trying to pratice some code to get a good feel of it before making a simple game engine. You know move left press down hey left etc etc. However I guess im just doing it wrong.

I was watching this video step by step but is it fake?
You Tube Video - platformer

Trouble is that its not doing anything. Its just sitting there and I apply the code right or I am just missing something?


Code:
onClipEvent (load){
speed = 5;
gravity = 0;
r = _height/2;
    jumping = false;
jumingheight = 15;
}
onClipEvent(enterFrame){
if(Key.isDown(Key.RIGHT))
_x+=speed;
     }
if(Key.isDown(Key.LEFT)){
_x -= speed;
       }
if(Key.isDown(Key.UP)&B !jumping){
if(!_root.ground.hitTest(_X,_Y, true)}{
gravity = -jumpheight;
jumping = true;
   }
   gravity++;
   _y +=gravity;
   } else {
   jumping = false;
gravity = 0;
}
While(_root.grounds.hitTest(_x,_y-1,true)){
jumping = false;
_y--;
}


Then there is also this cool Bouncing ball with particle effect and wind
Link to Tut - pretty cool
Logged
Snowman
Senior Member
****
Offline Offline

Gender: Male
Posts: 553


Save a plant, eat a vegetarian


« Reply #1 on: November 19, 2009, 05:57:16 PM »

The problem with your code is that there are a ton of little mistakes in it. I fixed your code and tested it, it'll work fine when you made the needed corrections. Just remember that when it comes to coding, attention to detail is a prerequisite. I'll let you try to figure out the mistakes you made so you can see how much of an impact the little stuff can be.

Coding is case-sensitive. If something is lower or upper case, it's for a reason. Also, try to realize the impact of using these {} instead of (). The direction these are facing matter as well. Good luck my man, if you need any additional help I'll guide you through it a little better. I gotta get some sleep now though.  Tongue
Logged

Vector
Resident Actionscript Guru
Assistant Admin
Heroic
****
Offline Offline

Gender: Male
Posts: 3803


~ Programmer | National Laser Tag Player | Bent ~


WWW
« Reply #2 on: November 19, 2009, 06:01:22 PM »

Disclaimer: It's been about 3 years since I've touched actionscript properly, so please bear with me... Smiley

From what I can see it looks a lot like AS1 code. It definitely won't work in an AS3 project, and you may or may not have luck in an AS2 project. The other thing with the onClipEvent code is that it has to be placed on the timeline *on* the object that you want to work with, which may be causing you some trouble. (ie, you click on the object, then bring up the actionscript window with F9).

Haven't looked at the tutorial video as I've got limited bandwidth, but from the code you've posted they're the two major things that stick out to me at the moment.

One thing you could try doing is giving your clip an instance name (let's use "myCharacter" for an example). Then, on the main timeline, you would replace
Code:
onClipEvent(load)
with
Code:
myCharacter.onLoad = function()

and
Code:
onClipEvent(enterFrame)
with
Code:
myCharacter.onEnterFrame = function()

I would also check that you have an equal number of left and right brackets and braces... Smiley that is the () and {}.

See how you go with that.
« Last Edit: November 19, 2009, 06:16:03 PM by Vector » Logged

~Vector
Brackenwood
   

 Logged
Pages: [1]   Go Up
Print
Jump to:  

Theme by Pieter, based on Black Rain by Crip Powered by SMF 1.1.15 | SMF © 2011, Simple Machines XHTML | CSS

Page created in 0.048 seconds with 24 queries.