Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Scripting Lesson: ? (https://forums.graalonline.com/forums/showthread.php?t=33050)

Graal518 07-07-2002 06:02 AM

Scripting Lesson: ?
 
?
This is a very useful little... thing. Kaimetsu taught me how to use it, and it comes in handy for things like switches, or turning on NPCs by firing it. Here is an example of how to use it.
NPC Code:

if (weaponfired) this.on = this.on==0?1:0;


You may be thinking "Wtf?", but here's how it works.
NPC Code:

if (weaponfired) this.on = this.on==0?1:0;


This section is basically like a flag checker. If this is true, it will do what's in front of the colon. If it's false, it will do what's behind it. The main purpose of this tool thingie is to shorten script.

You could do this without the ?, although it would be a bit longer
NPC Code:

if (weaponfired){
if (this.on==0){
this.on=1;
}else this.on=0;
}


Or... something. o.O!
Now back to the ? part.
Lets say you fire the weapon, and this.on equals 1. The flag checker thingie part will read this.on==0 as false, and do what's behind the colon, which is a 0. This.on will be set to 0. Got it? You'd better, cause i'm tired of typing.


-Wind Seablaze

Python523 07-07-2002 06:04 AM

this.on=(this.on+1)%2 - shorter

Graal518 07-07-2002 06:06 AM

Quote:

Originally posted by Python523
this.on=(this.on+1)%2 - shorter
Okay that just negated EVERYTHING I TYPED. Evil. ~_~

Falcor 07-07-2002 06:14 AM

Jagen, you do realise that it is unnecesary to run it through such a math equation don't you?

If it is on and off you could just as well do

this.on = abs(1-this.on*2);

Graal518 07-07-2002 06:19 AM

... =(

Falcor 07-07-2002 06:47 AM

thats a good thing to keep in mind tho Wind... Its something we do In C++ a lot. you could potentially do anything a normal ifelse can do (for setting a varaible atleast), and shorten it to 1 line. its good for compacting things.

this.var = (this.var > 3? 2 : this.var<2 1 : 0);
and what not.

Although you can also try doing just

this.var = (condition);
such as
this.var = (strequals(#n,Falados));
it would be true if your name was falados, and false if it isn't.
You could potentially do it for on/off variable aswell.

this.on = (this.on==0);
Im not sure graal will necesarily accept that. however it will probably accept this..
this.on=(strequals(0,#v(this.on)));

Graal518 07-07-2002 07:59 AM

Wind, not Cyn. Wind. =P
Cyn is letting me use his forums account, and his player soon. Cyn are no like Grawl nomores. =(

Falcor 07-07-2002 12:31 PM

I will make that change then :)


All times are GMT +2. The time now is 08:37 PM.

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