Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #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
  #2  
Old 07-07-2002, 06:04 AM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
this.on=(this.on+1)%2 - shorter
Reply With Quote
  #3  
Old 07-07-2002, 06:06 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
Quote:
Originally posted by Python523
this.on=(this.on+1)%2 - shorter
Okay that just negated EVERYTHING I TYPED. Evil. ~_~
__________________


Can there be a guiding light I've yet to see? I know my heart should guide me, but...
Reply With Quote
  #4  
Old 07-07-2002, 06:14 AM
Falcor Falcor is offline
Darth Cucumber
Falcor's Avatar
Join Date: Mar 2001
Location: At School
Posts: 2,874
Falcor is on a distinguished road
Send a message via ICQ to Falcor Send a message via AIM to Falcor Send a message via MSN to Falcor Send a message via Yahoo to Falcor
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);
__________________

subliminal message: 1+1=3
Reply With Quote
  #5  
Old 07-07-2002, 06:19 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
... =(
__________________


Can there be a guiding light I've yet to see? I know my heart should guide me, but...
Reply With Quote
  #6  
Old 07-07-2002, 06:47 AM
Falcor Falcor is offline
Darth Cucumber
Falcor's Avatar
Join Date: Mar 2001
Location: At School
Posts: 2,874
Falcor is on a distinguished road
Send a message via ICQ to Falcor Send a message via AIM to Falcor Send a message via MSN to Falcor Send a message via Yahoo to Falcor
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)));
__________________

subliminal message: 1+1=3

Last edited by Falcor; 07-07-2002 at 12:32 PM..
Reply With Quote
  #7  
Old 07-07-2002, 07:59 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
Wind, not Cyn. Wind. =P
Cyn is letting me use his forums account, and his player soon. Cyn are no like Grawl nomores. =(
__________________


Can there be a guiding light I've yet to see? I know my heart should guide me, but...
Reply With Quote
  #8  
Old 07-07-2002, 12:31 PM
Falcor Falcor is offline
Darth Cucumber
Falcor's Avatar
Join Date: Mar 2001
Location: At School
Posts: 2,874
Falcor is on a distinguished road
Send a message via ICQ to Falcor Send a message via AIM to Falcor Send a message via MSN to Falcor Send a message via Yahoo to Falcor
I will make that change then
__________________

subliminal message: 1+1=3
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:12 PM.


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