PDA

View Full Version : Turn-Based Fighting


Gridden
03-04-2009, 05:40 PM
Another project to try and learn actionscript, this time trying to use functions.

I have the normal .fla file, and i created a .as file to house external methods.

First, here is the .fla file:

include "Monster.as"

stop();
var generatedTarget:int;
var charName:String = new String("");
var monName:String = new String("");
//test

generatedTarget = decideTarget.call ();

if (generatedTarget == 0){
charName = "char1";
monName = "mon1";
Monster.attackTarget.call (char1, mon1);
}

if (generatedTarget == 1){
charName = "char2";
monName = "mon2";
Monster.attackTarget.call (char2, mon1);
}

And the .as file:

var target:int;
var monsterSpeed:int = 5;
var monsterName:String = new String("");
var characterName:String = new String("");

public function decideTarget ():int {
target = Math.random() ;
return (target);
}

public function attackTarget (monsterName, characterName): void {
var characterXAxis:int = characterName.x +60;
monsterName.x
while (monsterName.x != characterXAxis) {
while (monsterName.y != characterName.y) {
monsterName.y + monsterSpeed;
}
monsterName.x + monsterSpeed;
}
}

What i want this to do, is basically decide the target (from 2 targets) and simply move up to them. However, its giving me 2 errors called "1114: The public attribute can only be used inside a package." pointing towards the "public" keyword. I have no idea whats wrong here, i tought you HAD to write public to make functions accessible from outside the script?

Thanks for the input.

Gridden
03-04-2009, 07:34 PM
Tried it like this now:

package {

public class Monster {
var target:int;
var monsterSpeed:int = 5;
var monsterName:String = new String("");
var characterName:String = new String("");

function decideTarget ():int {
target = Math.random() ;
return (target);
}

function attackTarget (monsterName, characterName): void {
var characterXAxis:int = characterName.x +60;
monsterName.x
while (monsterName.x != characterXAxis) {
while (monsterName.y != characterName.y) {
monsterName.y + monsterSpeed;
}
monsterName.x + monsterSpeed;
}
}
}
}

Its now giving the error on run time:

"1037: Packages cannot be nested."

Gridden
03-04-2009, 09:28 PM
Come on, nobody?