Problems adding entity to world


#1

I am trying to add an entity to a world.

Here is the entity’s code:

public class lycanthrope extends Entity

{

	public var SprLycan:Spritemap = new Spritemap(Assets.Lycanthrope, 128, 128);
	
	public function lycanthrope
	{
		setHitbox (64, 64);
		
		sprLycan.add("waiting", [0, 1, 2, 3, 4, 5, 6, 7], 8, true);
		sprLycan.add("running", [8, 9, 10, 11, 12, 13, 14, 15], 8, true);
                graphic= sprLycan;
	}
	
	override public function update (): void
	{
	sprLycan.play("running", false, 0);
	
	x + 2;
	y + 2;
	}
}

Here is the world:

public class Test_World extends World

{

    public function Test_World() 

    {

        add (new(Player));

        add (new (lycanthrope));

    }

}

However, when I try to test, I get “Error: Access of Undefined Property Lycanthrope”.


(Martí Angelats i Ribera) #2

Remove the parentheses.

add(new Player);
add(new lycanthrope);

FTFY, i recomment to rename the class to Lycanthrope (starting with capital letter to show that it’s a class). It’s not mandatory and the code will work but it’s a pretty good practice (almost everyone uses it).


#3

Okay, thanks. I have implemented both of the suggested changes, but I still get an error, or rather three errors.

C:\Users\James\Documents\Test_Game\src\Lycanthrope.as(12): col: 3 Error: Syntax error: expecting leftparen before leftbrace. { ^

C:\Users\James\Documents\Test_Game\src\Lycanthrope.as(12): col: 3 Error: Syntax error: expecting identifier before leftbrace. { ^

C:\Users\James\Documents\Test_Game\src\Lycanthrope.as(12): col: 3 Error: Syntax error: expecting rightparen before leftbrace. { ^


(Martí Angelats i Ribera) #4

Need the code to know the bug but it seems that you made some kind of error with the spacers.

Try changing the line

override public function update (): void

for

override public function update():void

#5

package

{

import net.flashpunk.World;

public class Test_World extends World
{
	public function Test_World() 
	{
		add (new Player);
		add (new Lycanthrope);
	}
}

}

package

{

import net.flashpunk.Entity;
import net.flashpunk.graphics.Spritemap;
import net.flashpunk.FP;

public class Lycanthrope extends Entity
{
	public var SprLycan:Spritemap = new Spritemap(Assets.Lycanthrope, 128, 128);
	
	public function Lycanthrope
	{
		
		setHitbox (64, 64);
		
		sprLycan.add("waiting", [0, 1, 2, 3, 4, 5, 6, 7], 8, true);
		sprLycan.add("running", [8, 9, 10, 11, 12, 13, 14, 15], 8, true);
		graphic = sprLycan;
	}
	
	override public function update (): void
	{
	sprLycan.play("running", false, 0);
	
	x + 2;
	y + 2;
	}
}

}


(Martí Angelats i Ribera) #6

Try what i said in the last post


#7

Oh, yes, sorry.

Did that as well. Same 3 errors.

Edit: I changed “public function Lycanthrope” to “public function Lycanthrope()” and fixed the one instance of “SprLycan” to “sprLycan”. That fixed the problem.

Thank you for your assistance. I’m glad that this community is tolerant towards inexperienced users; I have ran into a few that were not.


(Martí Angelats i Ribera) #8

I highlly recomend to make a full AS3 tutorial before messing up with this kind of projects. You need the bases first (this errors was for lack of solid bases in AS3 and maybe programming in general).

Everyone had been a n00b. The first step to be good at something is to suck at it, right? :wink:


#9

What exactly do you mean by “make a full AS3 tutorial”?


(Martí Angelats i Ribera) #10

Sorry, my english sucks >.<.

I ment to follow one. Do it from the start to the end (no need for advanced stuff, though).

Oh, and write the code yourself, don’t copy-pase. To write the code is a good way of making less mistakes later on. Also make small tests allows you to learn more and deeper.


#11

No problem. I should have been able to infer that. I’m guessing that your native language is Portuguese. I could be wrong, and I do not mean to offend.

Thank you for the advice. You’re right. I probably should’ve acquainted myself better with ActionScript and with OOP in general before trying to use FlashPunk and build a full game.


(Martí Angelats i Ribera) #12

No problem! I’m here to help!

PS: My native language is actually catalan :stuck_out_tongue:

PPS: Thanks for pointing that error out. It helps me to improve my english.


(Mike Evmm) #13

Do familiarise yourself with OOP and AS3, but making games as a way of applying what you’ve learned has worked great for me!

(Also go Portugal :smiley: )