Author Topic: Save yourself a lot of time - Make The Switch!!  (Read 962 times)

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Save yourself a lot of time - Make The Switch!!
« Reply #15 on: August 31, 2010, 10:13:08 pm »


               *Woosh*  Thank Lightfoot8, I had serious scare there for a moment, thinking I was making some grave error in judgment or something...
               
               

               
            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
Save yourself a lot of time - Make The Switch!!
« Reply #16 on: August 31, 2010, 11:06:34 pm »


               

Genisys wrote...



(Edited)
This is designed to be a basic tutorial, showing scripters the importance of making switches (Constant Variables which control a script or multiple scripts) in scripts..

This is a very trivial tutorial, and would require basic knowledge of scripting.
(NOTE: Variable would be replaced with one of the following:   int / string / float)

Script A)    (No switch / Constant)

void main()
{
  //A Bunch of code will go here..

  variable a; //May Change
  variable b; //Does Not Change

 //Still yet more code may go here...
}

Script 'B)'     The Switches (Controls) / Constants go above #include "scriptname" & void main()

//Set the ? below to (what?), where ? = _____.  (You fill in the blanks)
//Tell yourself and others what changes to ? will effect)
const variable VARIABLE_X = ?;   

#include "somescript"

void main()
{
  //A Bunch of code will go here..

  variable a; //May Change
  variable b = VARIABLE_X;  //The Constant Unchanging Variable Above.. (VARIABLE_X = the name)

 //Still yet more code may go here...
}
':wizard:'



Genesys, 
    You are misusing the term totally. Please call a constant a constant and stop confusing others with invalid jargon. Also, in your examples NOTHING is hinging on any of the constants, so what exactly you are trying to pass on to others in this post I cannot even guess. 

':crying:'

In short   GAAAH!
               
               

               
            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
Save yourself a lot of time - Make The Switch!!
« Reply #17 on: September 03, 2010, 10:44:13 pm »


               

The Amethyst Dragon wrote...

ehye_khandee wrote...

just constants is all they are called. also, never use constants unless you absolutely NEED to, as there are a limit to the number you can use in a module, so why waste?


I've encountered a limit in constants in individual scripts (especially when using mutiple "#include" files), but is there a whole-module limit I missed somewhere?


I refuse to use an outside compiler for NWN, it is just my way. I helped tame a PRC server a while ago and was getting loads of issues out of it (lots of script cleaning ensued). I've also run into resource limits in the module as a whole when upgrading (sic) from CEP2.0 to 2.1 (and I will do that NEVER again). It was all down to constants of which there were way too many in the 2.1+ my module, and again, much script cleaning ensued.

IDK the exact limit, but it cuts into resources and I treasure resources, using it very very sparingly - I find I do no wrong that way.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Save yourself a lot of time - Make The Switch!!
« Reply #18 on: September 03, 2010, 11:56:26 pm »


               

ehye_khandee wrote...

Genesys, 
    You are misusing the term totally. Please call a constant a constant and stop confusing others with invalid jargon. Also, in your examples NOTHING is hinging on any of the constants, so what exactly you are trying to pass on to others in this post I cannot even guess. 

':crying:'

In short   GAAAH!


No he does not totally. Yes, he reffering to constants, however isn't constant like a constant.

There are special cases of constants that if you change them, changes behaviour of whole script. Many global scripts from vault uses that. If user do not like one feature there is constant-switch that after changing to 0 turn that feature off. I think the word switch is in proper place there.

Also the default bioware module load has special switch system, these switches are local variables actually, the good on them is that they do not require the affected script(s) to be compiled. But more experienced scripters tends just to place the variable on module by hand.

In my understanding, if there is anything that changes behaviour of the script(s) it may be named "switch". For example UO Abigail craftin system had material switches in the craftin placeables. If player took that switch, material was set up to silver etc.

Its not a ba technique, but personally I don't like too much global scripts (like Funky Swerve's SIM Tools) at all.:innocent:
               
               

               
            

Legacy_Invisig0th

  • Sr. Member
  • ****
  • Posts: 279
  • Karma: +0/-0
Save yourself a lot of time - Make The Switch!!
« Reply #19 on: September 06, 2010, 05:31:47 am »


               

ShaDoOoW wrote...

ehye_khandee wrote...

Genesys, 
You are misusing the term totally. Please call a constant a constant and stop confusing others with invalid jargon.

No he does not totally. Yes, he reffering to constants, however isn't constant like a constant.

There are special cases of constants that if you change them, changes  behaviour of whole script. Many global scripts from vault uses that. If  user do not like one feature there is constant-switch that after  changing to 0 turn that feature off. I think the word switch is in  proper place there.

Also the default bioware module load has special switch system, these switches are local variables actually, the good on them is that they do not require the affected script(s) to be compiled. But more experienced scripters tends just to place the variable on module by hand.

In my understanding, if there is anything that changes behaviour of the script(s) it may be named "switch".

Well then, your understanding is wrong. Yes, Bioware used the term "switches" to refer to their system of global values obtained from local variables on objects. However, that is not relevant here, because that is not what Genisys is doing. Genisys is simply setting constant variables at the beginning of scripts. No one who knows anything about computer programming would call what Genisys is doing here "switches". Everyone in this thread understands that except you.

You may use whatever made up terminology you like, but please don't try to tell those of us who are actually programmers that your made up terminology is correct.. I'll remind you that this is the scripting forum, and that insisting on using incorrect programming terminology is extremely unhelpful, because it confuses new people. Perhaps it is confusing you as well?
               
               

               


                     Modifié par Invisig0th, 06 septembre 2010 - 05:06 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Save yourself a lot of time - Make The Switch!!
« Reply #20 on: September 06, 2010, 06:02:48 am »


               I hate to dissagree but shadow is correct.   And yes the boiware system does set constants at the begining of there switches.  After all the name of every switch is constant.  They have different values set to the switch  (TRUE or FALSE).  But the Name of the modular var where it is stored is a constant.
               
               

               
            

Legacy_Invisig0th

  • Sr. Member
  • ****
  • Posts: 279
  • Karma: +0/-0
Save yourself a lot of time - Make The Switch!!
« Reply #21 on: September 06, 2010, 06:05:13 am »


               Irrelevant. I've already explained why.

As a professional Solution Architect with 15 years of computer programming experience, I can assure you that using the term "switches" here is incorrect, confusing, and counterproductive. But don't take my word for it -- ehye_khandee and GhostOfGod have also said the same thing above. What Genisys is talking about here is simply setting constants.

It has absolutely nothing to do with the Bioware system you mentioned at all. That is nothing but a red herring. Setting constants at the top of a script in the toolset (design time) is completely different from getting values from the localvars of objects (runtime). Apples and oranges.

If you want to insist on using incorrect terminology that does nothing but confuse people, then forgive me if I insist that you are wrong. This is the scripting forum, after all, and incorrect information helps no one.
               
               

               


                     Modifié par Invisig0th, 06 septembre 2010 - 05:21 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Save yourself a lot of time - Make The Switch!!
« Reply #22 on: September 06, 2010, 06:22:02 am »


               I Guess you should tell Bioware to change the name of there include to something other then x2_inc_switches then.
               
               

               
            

Legacy_Invisig0th

  • Sr. Member
  • ****
  • Posts: 279
  • Karma: +0/-0
Save yourself a lot of time - Make The Switch!!
« Reply #23 on: September 06, 2010, 06:27:34 am »


               Setting constants at the top of a script in the toolset (design time) is completely different from  getting values from the localvars of objects (runtime), which is what that Bioware script file does.

//----------------------------------------------------------------------------
// Return the value of a module switch set by SetModuleSwitch
// See X2_INC_SWITCHES for a list of all module switches
//----------------------------------------------------------------------------
int GetModuleSwitchValue(string  sModuleSwitchConstant)
{
    int nRet =  GetLocalInt (GetModule(),sModuleSwitchConstant);
    return nRet;
}

That is not what is being discussed in this thread. They are two completely different things. You are doing nothing but further confusing the issue.
               
               

               


                     Modifié par Invisig0th, 06 septembre 2010 - 05:37 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Save yourself a lot of time - Make The Switch!!
« Reply #24 on: September 06, 2010, 06:39:48 am »


               I can totally see how these constants can be viewed as "switches" though. They can indeed act as a switch in a script. Perhaps when referencing them in in your scripts Genisys, you can call em "constant switches" or something. Or in posts maybe "Constants being used as script switches". I don't know. Something that won't confuse people with an actual "switch" is all.

2 cents. Maybe only worth 1.'<img'>
               
               

               


                     Modifié par GhostOfGod, 06 septembre 2010 - 05:40 .
                     
                  


            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Save yourself a lot of time - Make The Switch!!
« Reply #25 on: September 06, 2010, 06:45:23 am »


               In the computer world a switch is a common term used to represent on/off switches, jumpers, or anything that controls something electronically by turning on or off the flow of electricity, like how resistors tell a computer a switch is on or off, computers essentially are a collection of switches, and as a programmer your probably aware that in the binary world everything is 1 or 0 on or off / yes or no (Machine level programming code), then of course if you look at memory everything is also 1 or 0, therefore, when someone says "switch", they simply refer to something which turns something on or off, or something that controls something.  

My use of the terminology isn't grossly wrong in this case, I'm calling a constant a switch because it controls the script, and it's common for multiple constants to be used to control a script or multiple scripts in many cases, switch isn't a bad term to use here, and just because I'm not "scientifically, technically or politically correct" doesn't mean my loose use of the word here doesn't mean it's lost on everyone.  In fact, I'm not the first person to call constants a switch, I've read this terminology in many scripts before..

Constants never change, by the lexicon definition, where a Constant Switch is nothing more than a constant that does change, by the user, to control a script or multiple scripts.  That's how I have always inturpreted what switches are, as controls, not only in coding, but in the computer world too...

I apologize for any mis-understanding I caused and I will do my best to clarify that in the first post..
               
               

               


                     Modifié par Genisys, 06 septembre 2010 - 06:17 .
                     
                  


            

Legacy_Invisig0th

  • Sr. Member
  • ****
  • Posts: 279
  • Karma: +0/-0
Save yourself a lot of time - Make The Switch!!
« Reply #26 on: September 06, 2010, 07:47:43 am »


               

Genisys wrote...
Constants never change, by the lexicon definition, where a Constant Switch is nothing more than a constant that does change, by the user, to control a script or multiple scripts.  That's how I have always inturpreted what switches are, as controls, not only in coding, but in the computer world too...

Genisys, you've been very considerate since this confusion regarding terminology was pointed out to you. I am very sorry that several people who are apparently less familiar with these things are confusing the issue for you. But if you wish other people to clearly understand what you are doing here, then simply say  that you are setting up constants to simplify your code. Everyone will understand that perfectly, and it will not be confusing to anyone..

However, one thing you stated above is completely incorrect:
"Constants never change, by the lexicon definition, where a Constant Switch is nothing more than a constant that does change, by the user, to control a script or multiple scripts."

No, that is completely wrong. "Constants" are values that can be changed by the scripter ("user" or programmer) in the toolset before the game is played. What the Lexicon is saying is that once you as the scripter declare something as a constant ("const"), then the script will not compile if you try to change the value later in that script. If a constant couldn't be changed by the programmer as needed, it wouldn't be much use, would it?

What you did in the first thread of this post is a *textbook* example of what constants are used for in programming. The examples that programming students see in their freshman classes look almost identical to what you did. A constant is a value that you set in your code so that you don't have to go through your code making changes in different places if that value changes. Instead, you just set it *once* at the beginning. To make sure you don't accidentally change it later in that script, you add the "const" keyword.

Three different experienced programmers have told you this in this thread, and it is 100% correct.

There is nothing wrong with misusing a term once in a while, partiularly when you are just beginning. And this is not at all about picking on people who are not programmers. Not everybody is a computer programmer, nor do they need to be.

But when several more experienced people tell you that the term you are using is really confusing to others, then perhaps there is some value in using the correct term moving forward. And the term for what you're doing here is simply setting constants in the toolset to control aspects your script, and then changing those constants in the toolset if the script functionality needs to change.

You can call them "switches" if you like, but that is just going to confuse people and make it harder for them to appreciate what you are trying to do here. And that really doesn't help anyone.
               
               

               


                     Modifié par Invisig0th, 06 septembre 2010 - 06:51 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Save yourself a lot of time - Make The Switch!!
« Reply #27 on: September 06, 2010, 07:51:41 am »


               

You may use whatever made up terminology you like, but please don't try
to tell those of us who are actually programmers that your made up
terminology is correct.. I'll remind you that this is the scripting forum, and that insisting on using incorrect programming terminology is extremely unhelpful, because it confuses new people.

Question is. What are we talking about? NWScript techniques and NWScript terminology or high programming techniques and terminology.
               
               

               
            

Legacy_Invisig0th

  • Sr. Member
  • ****
  • Posts: 279
  • Karma: +0/-0
Save yourself a lot of time - Make The Switch!!
« Reply #28 on: September 06, 2010, 07:55:51 am »


               Three experienced programmers have already stated in this thread that the term "switch" is very confusing and potentially counterproductive. Using that particular term makes it more difficult for people (particularly beginners) to understand what Genisys is doing here. And that is a shame, because the technique itself is a very useful technique, and many people could benefit from learning more about it.

Would you prefer that people easily understand the technique that Genisys is using here, or do you honestly think it is better to confuse people? Because you are appear to be arguing  in favor of confusion. Anyone reading this thread should seriously think about whether you are actually trying to help here or not.

I won't be discussing this with you further "shadooow". You're clearly more concerned about  trying to win an argument rather than being concerned about helping people better understand scripting.
               
               

               


                     Modifié par Invisig0th, 06 septembre 2010 - 07:13 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Save yourself a lot of time - Make The Switch!!
« Reply #29 on: September 06, 2010, 08:06:34 am »


               The "scripts" of our lives.

As the "constant" turns.

One "script" to live.

Young and "Switch"less?

':lol:' Sorry. I couldn't help myself.
               
               

               


                     Modifié par GhostOfGod, 06 septembre 2010 - 07:07 .