View Full Version : Messy code, please help me clean!
SNOWmanx
May 14th, 2006, 06:26 PM
Alright guys, I have this really messy code that I just can't get cleaned.
// P R E L O A D V A R I A B L E S
function loadVars(target, team):Void {
var playerVar:Object = new Object();
playerVar = eval(target);
playerVar.team = team;
playerVar.hp = 2;
playerVar.moveSpeed = 4;
playerVar.xSpeed = 0;
playerVar.ySpeed = 0;
playerVar.vRotation = 0;
playerVar.hRotation = 0;
playerVar.rotation = 0;
playerVar.vMove = false;
playerVar.hMove = false;
playerVar.action = false;
playerVar.isLoaded = true;
playerVar.charState = "idle";
playerVar.waitShot = null;
playerVar.coolDown = 0;
playerVar.coolDownRate = 3.7;
playerVar.coolDownInit = false;
playerVar.shotInit = false;
playerVar.reload = 0;
playerVar.reloadRate = .5;
playerVar.reloadInit = false;
}
I've tried using with() and telltarget(), but those gave me no results. Either I'm doing it wrong, or I don't know the proper use of the two above functions. Please help me out!
nathan99
May 15th, 2006, 07:59 AM
What do you mean by clean?... FLA?
Joppe
May 15th, 2006, 10:12 AM
^^ I'd say thats clean.. :S
Templarian
May 15th, 2006, 04:20 PM
also confused.
// P R E L O A D V A R I A B L E S
function loadVars(target, team):Void {
var playerVar:Object = new Object();
playerVar = eval(target);
with(playerVar){
team = team;
hp = 2;
gay = true;
moveSpeed = 4;
xSpeed = 0;
ySpeed = 0;
vRotation = 0;
hRotation = 0;
rotation = 0;
vMove = false;
hMove = false;
action = false;
isLoaded = true;
charState = "idle";
waitShot = null;
coolDown = 0;
coolDownRate = 3.7;
coolDownInit = false;
shotInit = false;
reload = 0;
reloadRate = .5;
reloadInit = false;
}
}
joran420
May 15th, 2006, 07:23 PM
It looks fine to me maybe comment it out a little more
[edit] actually the var names are probably plenty of commenting as they are fairly self explanatory
sslaby
May 15th, 2006, 08:32 PM
I don't think it's messy. Besides using with, there really isn't a way to make it much cleaner.
Even without using with, it's easy to read/understand since it's pretty much just initializing variables.
TheCanadian
May 15th, 2006, 09:29 PM
also confused.
// P R E L O A D V A R I A B L E S
function loadVars(target, team):Void {
var playerVar:Object = new Object();
playerVar = eval(target);
with(playerVar){
team = team;
hp = 2;
gay = true;
moveSpeed = 4;
xSpeed = 0;
ySpeed = 0;
vRotation = 0;
hRotation = 0;
rotation = 0;
vMove = false;
hMove = false;
action = false;
isLoaded = true;
charState = "idle";
waitShot = null;
coolDown = 0;
coolDownRate = 3.7;
coolDownInit = false;
shotInit = false;
reload = 0;
reloadRate = .5;
reloadInit = false;
}
}
The property has to already exist withing the object before referencing it with the with statement.
The only thing that really doesn't make a lot of sense is where you define playerVar as an object then overwrite it in the next line with the return from eval.
JoshuaJonah
May 15th, 2006, 09:32 PM
true. I saw that and wondered what the reasoning was, but it doesn't really make the code any more cluttered.
Templarian
May 15th, 2006, 10:04 PM
The property has to already exist withing the object before referencing it with the with statement.
The only thing that really doesn't make a lot of sense is where you define playerVar as an object then overwrite it in the next line with the return from eval.
Yea i dont know what i was thinking.
nathan99
May 16th, 2006, 03:09 AM
haha mer too, thought maybe i was just stupd
SNOWmanx
May 16th, 2006, 08:22 PM
My bad. What I meant by clean was that normally, your variables are defined with var, correct? These aren't, and I can't get them to... so I was wondering if if would hinder some aspects of the game.
TheCanadian
May 16th, 2006, 09:08 PM
My bad. What I meant by clean was that normally, your variables are defined with var, correct? These aren't, and I can't get them to... so I was wondering if if would hinder some aspects of the game.
All the var statement does is make a variable local to the function that it is declared in. That is it gets deleted after the function call. Other than that there really is no point in using it. Example:
function test():Void {
var localVariable:String = new String("i'm local");
publicVariable = new String("i'm not local");
}
test();
trace(localVariable); //undefined
trace(publicVariable); //i'm not local
I suppose it's also useful if you want to define variable type. But you can't use the var statement and define the variable in the scope of an object other than this.
hybrid101
May 18th, 2006, 10:50 AM
actually, i think it's already clean too:)
messy = hard to read/understand
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.