View Single Post
  #1  
Old 07-07-2002, 06:02 AM
Graal518 Graal518 is offline
Foolish Dreamer
Graal518's Avatar
Join Date: Dec 2001
Location: Montana
Posts: 2,140
Graal518 is on a distinguished road
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
__________________


Can there be a guiding light I've yet to see? I know my heart should guide me, but...
Reply With Quote