Advertising (This ad goes away for registered users. You can Login or Register)

PLEASE DELETE

Programming on your favorite platform, for your favorite platform? Post here
Post Reply
TheGuardian
Posts: 22
Joined: Sat Oct 29, 2011 4:25 am

PLEASE DELETE

Post by TheGuardian » Mon Jul 16, 2012 3:06 am

I solved already! turned out that I was missing an = sign.
Thank for the help!
Advertising
Last edited by TheGuardian on Tue Oct 02, 2012 5:31 pm, edited 2 times in total.

User avatar
codestation
Big Beholder
Posts: 1660
Joined: Wed Jan 19, 2011 3:45 pm
Location: /dev/negi

Re: problem with actionscript code

Post by codestation » Mon Jul 16, 2012 5:29 am

This is the problem? (marked in red, the variable has a typo)
//make variables to store key states
var kUp = false;
var kDown = false;
var kLef = false;
var kRight = false;
Advertising
Plugin list
Working on: QPSNProxy, QCMA - Open source content manager for the PS Vita
Playing: Error: ENOTIME
Repositories: github, google code
Just feel the code..

TheGuardian
Posts: 22
Joined: Sat Oct 29, 2011 4:25 am

Re: problem with actionscript code

Post by TheGuardian » Mon Jul 16, 2012 1:50 pm

Thank You! It did actually solved some of my errors, but new ones showed up. I figured them out since they were inconsistent caps and stuff like that. Now I have this problem
Whenever I run the program it does not show any errors on the compiler and runs fine. Yet, I can't control the freaking character. I will paste the code, but I think I am forgetting something besides the code! As I said before the compiler shows no errors, but I can't control my character!

Code: Select all

import flash.events.KeyboardEvent;
import flash.events.Event;

//some variables to track the player's speed
var speedX=0;
var speedY=0;

//loop through all platform objects to generate a level

var level:Array = new Array();
for (var i=0; i<numChildren; i++)
{
	if (getChildAt(i) is PLatform)
	{
		level.push(getChildAt(i).getRect(this));
		
	}
}

//make variables to store key states
var kUp = false;
var kDown = false;
var kLeft = false;
var kRight = false;

//listen for key presses and releases
stage.addEventListener(KeyboardEvent.KEY_DOWN, kD);
stage.addEventListener(KeyboardEvent.KEY_DOWN, kU);
function kD(k:KeyboardEvent)
{
	if (k.keyCode == 37) kLeft=true;
	if (k.keyCode == 38) kUp=true;
	if (k.keyCode == 39) kRight=true;
	if (k.keyCode == 40) kDown=true;
}
function kU(k:KeyboardEvent)
{
	if (k.keyCode == 37) kLeft=false;
	if (k.keyCode == 38) kUp=false;
	if (k.keyCode == 39) kRight=false;
	if (k.keyCode == 40) kDown=false;
}

//make a looping function
addEventListener(Event.ENTER_FRAME, loop);
function loop(e:Event)
{
//lateral movement checks
if (kLeft)
{
	speedX=-10;
}
else if (kRight)
{
	speedX=10;
}
else
{
	speedX*=0.5; //friction
}

//move player based on the above
Animation.x+=speedX;
//sidewards hit tests
for(i=0; i<level.length; i++)
{
	if (Animation.getRect(this).intersects(level[i]))
	{
		
	if (speedX > 0) //moving right
	
	{
		Animation.x = level[i].left - Animation.width/2;
	}
	if (speedX < 0) //moving left
	{
		
	Animation.x = level[i].right + Animation.width/2;
	}
	speedX; //kill the speed
	}
	}
}
//vertical checks
speedY+=1;
Animation.y+speedY;
var jumpable=false;

//hit tests
for (i=0; i<level.length; i++)
{
	if (Animation.getRect(this).intersects(level[i]))
	{
		if (speedY>0) //moving down
		{
			Animation.y=level[i].top-Animation.height/2;
			speedY=0
			jumpable=true;
		}
		if (speedY<0) //moving up
		{
			Animation.y=level[i].bottom+Animation.height/2;
			speedY*=-0.5; //bounce off the ceiling
			
		}
		speedX=0;
	}
}
if (kUp && jumpable) //jump if possible
{
	speedY=-15
}
Last edited by Xian Nox on Thu Jul 19, 2012 1:43 pm, edited 1 time in total.
Reason: Added code tags

User avatar
codestation
Big Beholder
Posts: 1660
Joined: Wed Jan 19, 2011 3:45 pm
Location: /dev/negi

Re: problem with actionscript code

Post by codestation » Mon Jul 16, 2012 3:59 pm

Why don't add some logging to see if is working properly. Use the debugger if you feel brave (I worked in AS2 for a couple of years and their horrible debugger made me cry, cannot recommend it unless is an emergency).
Plugin list
Working on: QPSNProxy, QCMA - Open source content manager for the PS Vita
Playing: Error: ENOTIME
Repositories: github, google code
Just feel the code..

User avatar
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: problem with actionscript code

Post by m0skit0 » Thu Jul 19, 2012 9:48 am

Dude, DO NOT EDIT THE OP. Now who the heck knows what the original question was... :roll:
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"

User avatar
fate6
Big Beholder
Posts: 7599
Joined: Fri Mar 09, 2012 1:18 am
Location: [fate6@Canterlot ~]$

Re: problem with actionscript code

Post by fate6 » Thu Jul 19, 2012 10:54 am

that^

but next time please put such big posts in spoilers, this includes your second post BTW ;)
Image
anon wrote:If you can't trust a 600 year old vampire in a prepubescent girl's body, who can you trust?

User avatar
Xian Nox
Retired Mod
Posts: 2749
Joined: Fri Nov 05, 2010 5:27 pm
Location: Over the hills and far away

Re: problem with actionscript code

Post by Xian Nox » Thu Jul 19, 2012 1:42 pm

Oh I hate it when they do that. Google seems to have lost the cached copy too.
fate6 wrote:but next time please put such big posts in spoilers, this includes your second post BTW ;)

Code: Select all

 tags are better. *edits second post*

TheGuardian
Posts: 22
Joined: Sat Oct 29, 2011 4:25 am

Re: problem with actionscript code

Post by TheGuardian » Tue Aug 28, 2012 1:44 am

sorry about that guys,, My mistake. I did not know since I don't post that much.

Post Reply

Return to “Programming”