Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   New Scripters: Read! (https://forums.graalonline.com/forums/showthread.php?t=37929)

emortylone 09-14-2002 11:25 AM

New Scripters: Read!
 
If you're new to scripting, there is one major thing you need to keep in mind. It is better to use variables instead of definitive values. Let me explain:
NPC Code:

if (timeout)
{ if (keydown(0) && strequals(#s(client.string),1))
{ setstring client.string,2;}
if (keydown(0) && strequals(#s(client.string),2))
{ setstring client.string,3;}
if (keydown(0) && strequals(#s(client.string),3))
{ setstring client.string,4;}
if (keydown(0) && strequals(#s(client.string),4))
{ setstring client.string,1;}
timeout=0.1;
}


take THAT where you are setting it to a certain value, which makes editing a SUPER BISH or this:
NPC Code:

if (timeout)
{ if (keydown(0)
{ setstring client.string,#v(#s(client.string)+1);}
if (strtofloat(#s(client.string))=>5)
{ setstring client.string,1;}
timeout=0.1;
}


that makes it so that you have a LOT less coding, and can change things. I put that if the tsring is equal to OR GREAT THAN for a reason. If by some MISHAP or something you end up with 6 or something, then it wouldn't work. I try and build in 'extra protection' so incase something crazy happens and you have a glitch, it still works :D And when you're doing things, and the same actions will be repeated by more than one event, I find it best to use functions. If you need help with strings and/or this.vars read www.projectshifter.com more coming soon
---Shifter

Torankusu 09-14-2002 11:37 AM

I really hate that format/style.

I knew that, but thanks anyway.

Graal2001_NAT 09-14-2002 11:47 AM

if you wanted to be a nut about shortening, you could just do
test = (strtofloat(#s(client.string))+1)%6;
setstring client.string,#v(test);

R0b1n-NPC 09-14-2002 12:58 PM

eheheheh

WanDaMan 09-14-2002 03:06 PM

Quote:

Originally posted by R0b1n-NPC
eheheheh
<3 sig!

Graal2001_NAT 09-14-2002 09:21 PM

Quote:

Originally posted by Kaimetsu


But of course that'd only be shorter, and not necessarily more efficient or readable.

i myself consider whatever is shorter, more efficent, as long is there isnt any noticable processing time, which I don't think there is =x

gokux33 09-14-2002 10:59 PM

Quote:

Originally posted by Kaimetsu


Efficiency and shortness of code are completely different things. Shortness does not imply efficiency. And yeah, the different might not add up to much, but the readability factor is important too.

Unless you don't want people stealing things from your scripts.

adam 09-15-2002 04:05 AM

Quote:

Originally posted by Kaimetsu


Well, the solution there is to just code things too complicated for stupid people to understand, even with readable code.


Well if they understood it then they could make it themselves and that really isn't stealing is it? hmm.... Well I suppose stealing an idea for a script is possible. but I wouldnt' care as long as they were capable of doing it all on thier own.

Falcor 09-15-2002 05:44 AM

test = strtofloat(#s(client.string))+1;
if(test>=6) test=0;
setstring client.string,#v(test);

there, compromise.
Modules in this case do unnessisary math.

emortylone 09-16-2002 11:32 AM

Heh, I get confused by my own script 90% of the time, LMAO. Like my new class selection script for my PW. It spins and you can only see one at a time, fades, all leet cool uber stuff :P Keydown, all the greats in it ;) But I just TOTALLY got confused after sleeping... if I don't do a script 90% or more in one sitting, I usually never finish it, lmao
---Shifter


All times are GMT +2. The time now is 05:44 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.