Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by vicknick. 06/13/24 08:51
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 718 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19059 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Help me improve my code #157811
09/29/07 17:42
09/29/07 17:42
Joined: Oct 2006
Posts: 45
J
juggalo10101 Offline OP
Newbie
juggalo10101  Offline OP
Newbie
J

Joined: Oct 2006
Posts: 45
i've just been immersed in the world of lite-C
what tips do you have to help me improve some of my code before i get too in depth
Code:
 
#define health skill1
#define ammo skill2
#define maxammo skill3
#define weaponid skill4
#define topweapon skill5 //topmost weaponid user or enemy has

action player1 {
player = my;
my.health = 100;
my.ammo = 32;
my.weaponid = 1;
my.topweapon = 1;
if (my.health=>100){
my.health=100;
}
if (my.ammo =<1) {
reload();
}
if (my.weaponid==1){
my.maxammo = 32;
}
function reload (){
my.ammo = my.maxammo;
}
}



Last edited by juggalo10101; 09/29/07 17:44.
Re: Help me improve my code [Re: juggalo10101] #157812
09/29/07 18:24
09/29/07 18:24
Joined: Aug 2005
Posts: 390
Florida
O
oldschoolj Offline
Senior Member
oldschoolj  Offline
Senior Member
O

Joined: Aug 2005
Posts: 390
Florida
the first thing I would do is take all of your defines and capatalize them, this makes them easy to see in the rest of the code:

Here is how i set up my defines:
Code:
//Interaction
#define ATTACKABLE skill1
#define TEAM skill2
#define LEVEL skill3
#define CLASS skill4
#define DRUID 1
#define FIGHTER 2
#define HEALER 3
#define MAGICIAN 4
#define SCOUT 5
#define THIEF 6

//Ranges
#define SCAN_RANGE skill5
#define AGGRO_RANGE skill6



And how I see it in the code:

Code:
action players_code ()
{
player = my;

//Keep me on the ground
attach_to_ground_player();

//Interaction
if(!my.ATTACKABLE) my.ATTACKABLE = 1; //Player is attackable
if(!my.TEAM) my.TEAM = 2; //Player team
if(!my.LEVEL) my.LEVEL = 1; //Player level
if(!my.CLASS) my.CLASS = FIGHTER; //Player class



That's just personal preference. The second thing I would do is get use to "for" loops for doing checking, counting, etc. The are faster than while loops and also need less code.

You look like you have a good start, but i would take my initial values for the player and put them at the top, and then take all of the values that can change during gaemplay, and put them in a while loop, such as:

Code:
while (player != NULL)
{
if (my.health=>100) my.health=100;
if (my.ammo =<1) reload();
if (my.weaponid==1) my.maxammo = 32;
}



Also if you notice, I don't have brackets after those if statements. Save ya bit of time, becaue if you only have ONE instruction after an "if" statement, you don't need to include brackets.

Good Luck!!!

Jesse


you can find me with my face in the keyboard, unshaven, listening to some nameless techno tragedy, and hashing through code over a cold cup a stale joe. __________________________________ yours truly
Re: Help me improve my code [Re: oldschoolj] #157813
09/29/07 18:49
09/29/07 18:49
Joined: Oct 2006
Posts: 45
J
juggalo10101 Offline OP
Newbie
juggalo10101  Offline OP
Newbie
J

Joined: Oct 2006
Posts: 45
ah thanks alot

Re: Help me improve my code [Re: juggalo10101] #157814
09/29/07 18:53
09/29/07 18:53
Joined: Aug 2005
Posts: 390
Florida
O
oldschoolj Offline
Senior Member
oldschoolj  Offline
Senior Member
O

Joined: Aug 2005
Posts: 390
Florida
NP man, anytime you need help just ask, I know how hard i was to start with litec. I had no expereince in cscript either, so it sucked!


you can find me with my face in the keyboard, unshaven, listening to some nameless techno tragedy, and hashing through code over a cold cup a stale joe. __________________________________ yours truly
Re: Help me improve my code [Re: oldschoolj] #157815
09/29/07 19:31
09/29/07 19:31
Joined: Oct 2006
Posts: 45
J
juggalo10101 Offline OP
Newbie
juggalo10101  Offline OP
Newbie
J

Joined: Oct 2006
Posts: 45
yeah i get some of it but i just need to work out the synthax


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1