Aller au contenu

Photo

Save yourself a lot of time - Make The Switch!!


  • Veuillez vous connecter pour répondre
37 réponses à ce sujet

#26
Genisys

Genisys
  • Members
  • 525 messages
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 .


#27
Invisig0th

Invisig0th
  • Members
  • 170 messages

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 .


#28
Shadooow

Shadooow
  • Members
  • 4 468 messages

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.

#29
Invisig0th

Invisig0th
  • Members
  • 170 messages
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 .


#30
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
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 .


#31
Genisys

Genisys
  • Members
  • 525 messages
B)

GhostOfGod wrote...

The "scripts" of our lives.

As the "constant" turns.

One "script" to live.

Young and "Switch"less?

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


:blink:

I approve!  :D

#32
Redunct

Redunct
  • Members
  • 49 messages
It seems like you're trying to make functions.

Let me give you an example:

//In this script, we will create a function to identify if the player has a certain set of varriables.
//Note, that this should only be done with someone you will use often.
int IsDMillia(object oPC)
{
//Declare Variables
int i;
//First, we will see if the player is a member of this group. We will use a local
//int to identify this. Also, if this is false, we will cut the script at that
//point and return the result 1.
if (GetLocalInt(oPC,"IsDMillia")!=1)return i;
i++;
//Next, we'll check to see if the player did anything to upset this faction.
//We can place something somewhere else to allow them to make up for this,
//Or whatever else we may want to do. We will do the same thing as before.
if (GetLocalInt(oPC,"IsInTrouble")==1)return i;
i++;
//After that, we will check to see if the player is wearing his uniform.
object oChest;
oChest = GetItemInSlot(INVENTORY_SLOT_CHEST,oPC);
if (GetTag(oChest)!="DMilliaUniform")return i;
i++;
//Finally, we want to look for a certain integer, let's say for this case the integer
//Represents completing an objective.
if (GetLocalInt(oPC,"didjob")==1)i++;
return i;
}


Save that script as "xc_check_faction".

Then, for an example of an event script:

//Include the script we just made:
#include "xc_check_faction"

//This script will be ran we the player tries to enter the factions head quarters.
//The Guard will be the one who opens the door. Clicking on the guard is used to open the door.
//What the Guard actually does depends on the players condition.
void main()
{
object oPC;
oPC = GetClickingObject();
int x;
x = IsDMillia(oPC);
object oDoor;
oDoor = GetObjectByTag("DMilDoor");
switch (x)
{   //If not a member, the guard will attack.
    case 0:
    ActionAttack(oPC);
    break;
    //If a member but in trouble, the guard will tell the player to get lost, he's
    //not welcome.
    case 1:
    ActionSpeakString("You have some nerve showing your face. You're not welcome here, traitor.");
    break;
    //If a member but not wearing outfit, the Guard will tell the player to put his uniform on.
    case 2:
    ActionSpeakString("Look, buddy, I don't care what you wear at the local inn but 'round here you will dress right.");
    break;
    //If everything is right with the character BUT the character did not finish his job.
    case 3:
    ActionSpeakString("The boss isn't gonna wanna see you until you finish your job. You better finish. Now.");
    break;
    //If mission is complete, guard will open door.

    case 4:
    ActionSpeakString("Bout' time you're back. Boss wants to see you.");
    ActionUnlockObject(oDoor);
    ActionOpenDoor(oDoor);
    break;
}
}


You can, of course, do a variatey of things with this now, including custom conversation scripts amongst members.

#33
Genisys

Genisys
  • Members
  • 525 messages
Redunct, that will only server to confuse the reader further, it's not even remotely close to what I was showing, I was showing how to use constants to control the results of a script, by outlining to the script reader that you can use constants to control a script, which makes it easier for a scripter to modify a script to control how the script functions essentially.

Where the above argument started was me calling the constants = switches, so to clarify my statement, which was spurred upon the title, more than giving constants another name, I'm using constants as control switches to turn functions on / off or to change how something within the coding of script works...

example:

//Set this # to control what level the PC must be in order for this to happen
const int THIS_CONSTANT = 5;

void main()
{

 object oPC = GetLastUsedBy();

 int nVar = GetHitDice(oPC);

//if the PC is the level set above, then do this...
if (nVar == THIS_CONSTANT)
 {
    //do this..
 } 
}

Very simple scripting, truly..

Modifié par Genisys, 06 septembre 2010 - 10:15 .


#34
Redunct

Redunct
  • Members
  • 49 messages

Genisys wrote...

Redunct, that will only server to confuse the reader further, it's not even remotely close to what I was showing, I was showing how to use constants to control the results of a script, by outlining to the script reader that you can use constants to control a script, which makes it easier for a scripter to modify a script to control how the script functions essentially.

Where the above argument started was me calling the constants = switches, so to clarify my statement, which was spurred upon the title, more than giving constants another name, I'm using constants as control switches to turn functions on / off or to change how something within the coding of script works...

example:

//Set this # to control what level the PC must be in order for this to happen
const int THIS_CONSTANT = 5;

void main()
{

 object oPC = GetLastUsedBy();

 int nVar = GetHitDice(oPC);

//if the PC is the level set above, then do this...
if (nVar == THIS_CONSTANT)
 {
    //do this..
 } 
}

Very simple scripting, truly..


Why not just declare 5? It seems like that is a big waste of time if all you're doing is making a constant for 5. Hell, writing 5 is about as simple as you can get.

void main()

{



 object oPC = GetLastUsedBy();



 int nVar = GetHitDice(oPC);



//if the PC is the level set above, then do this...

if (nVar == 5)

 {

    //do this..

 } 

}

From what I saw, you were trying to Declare a universal varriable, which can be applied in multiple situations, in which case declaring a function would be a million times simpler, plus, it would allow for more control in what it does. If your variable already has a default function that would run it, just use that. The only case you would use constants is for something that would never change. There's no point in doing what you just showed me. Why declare 5 as a constant?

If you're saying the stuff above the constant does something to reach 5, it would be much simpler and more productive to use a custom function.


I'm just not seeing where you're coming from. Show me an example of usage of a constant that would make things easier were a function wouldn't serve better.

#35
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
Something like this, redunct:

//////////////////////////////GOGS AutoAFK System///////////////////////////////
//Name: "gogs_afk_inc"
//Date: 8-4-2010
//Type: include
////////////////////////////////////////////////////////////////////////////////
#include "x3_inc_string"
/////////////////////////////CONFIGURABLE OPTIONS///////////////////////////////

                             //!!!IMPORTANT!!//
//!!Be sure to "Build" you module after making any changes to this script!!

//Set timer for chat check and movement detection. After this time has expired
//for both checks then the AFK effect type will be applied.
//Default: 600 seconds(10 minutes)
const int TIMER = 600;//Seconds
//If using the RP XP option, decreasing the chat timer will mean that players
//will have to chat more often to recieve the XP reward.
const int CHAT_TIMER = 600;//Seconds

//Available AFK types:
//1 = Repeating floating text on player.
//2 = A visual effect will be applied to the player.
//3 = Transport player to an object in AFK area.
//4 = Boot player.
//5 = Play Animation(looping type only).
const int AFK_TYPE = 1;

//Options for AFK_TYPE 1:
//Enter message that you want to float over the players head when he/she is AFK.
//Default: "AFK"
const string AFK_FLOATING_MESSAGE = "AFK";
//Change the color of the floating text. Options for colors:
//STRING_COLOR_BLACK
//STRING_COLOR_BLUE
//STRING_COLOR_GREEN
//STRING_COLOR_PINK
//STRING_COLOR_RED
//STRING_COLOR_ROSE
//STRING_COLOR_WHITE
const string FLOATY_COLOR = STRING_COLOR_RED;
//Allow floaty text with all AFK types. Default: FALSE
const int FLOATY_TEXT_ALWAYS = FALSE;

//Option for AFK_TYPE 2:
//Enter desired VFX number or constant. Default: VFX_DUR_FLAG_GOLD
const int AFK_EFFECT = VFX_DUR_FLAG_GOLD;

//AFK OBJECT. This object is used for AFK_TYPE 2 and AFK_TYPE 3.
//Simply pick any placeable of your choosing and give it the tag below.
//Also make sure the object is checked "plot".If using the object for TYPE 2 you
//can put it in any area. If using it for TYPE 3 place it in the AFK area that
//players will be teleported to.
//Note for AFK_TYPE 3: This option sets a location on the player that they can
//be auto-ported back to. However should the player log out and log back in or
//if the server crashes, this location will be lost. Therefore you should have
//an alternate way of leaving the AKF area.
//Default: "GOGS_AFK_OBJECT"
const string AFK_OBJECT = "GOGS_AFK_OBJECT";
//Additional note for AFK type 3: I have made it so that a player who is in the
//AFK area must type something/anything in the chat bar for them to return to
//their stored location. This is to prevent other players from simply pushing
//the player around and causing a change in location which would teleport them.
//A repeating message is sent to the player until they type something.
//Message:
const string AFK_AREA_MESSAGE = "Type anything in the chat bar to be ported back to saved location.";
//Select color of message. Same color options as above apply.
const string AREA_MESSAGE_COLOR = STRING_COLOR_RED;

//Option for AFK_TYPE 5:
//Enter desired looping animation constant for the AFK animation.
//Default: ANIMATION_LOOPING_SIT_CROSS
const int AFK_ANIMATION = ANIMATION_LOOPING_SIT_CROSS;

//Send a message to the party members of the player that is AFK. This will
//display a message once when the player has gone AFK and once when the player
//is no longer AFK.
//If TRUE, message will be displayed to all party members. DEFAULT: TRUE
const int SEND_FACTION_MESSAGE = TRUE;
//Select color of message. Same color options as above apply.
const string FACTION_MESSAGE_COLOR = STRING_COLOR_PINK;

//Options for awarding RP XP. Basically, if the player is not AFK and has
//chatted within the last timer delay, the player will receive XP.
//Set to TRUE to give RP XP.
const int RP_XP_REWARD = FALSE;
//Set desired amount of XP to give every cycle.
const int XP_AMOUNT = 100;

////////////////////////////END CONFIGURABLE OPTIONS////////////////////////////

////////////////////////////////////////////////////////////////////////////////
void SendAFKFactionMessage(object oPC)
{
.............


Changing the constants in the beginning of the script will change how the script works below it. Thus acting as a kind of switch. And of course doing this allows for easy customization for other people who might use the script/system.

Modifié par GhostOfGod, 07 septembre 2010 - 01:44 .


#36
Redunct

Redunct
  • Members
  • 49 messages

GhostOfGod wrote...

Something like this, redunct:

//////////////////////////////GOGS AutoAFK System///////////////////////////////
//Name: "gogs_afk_inc"
//Date: 8-4-2010
//Type: include
////////////////////////////////////////////////////////////////////////////////
#include "x3_inc_string"
/////////////////////////////CONFIGURABLE OPTIONS///////////////////////////////

                             //!!!IMPORTANT!!//
//!!Be sure to "Build" you module after making any changes to this script!!

//Set timer for chat check and movement detection. After this time has expired
//for both checks then the AFK effect type will be applied.
//Default: 600 seconds(10 minutes)
const int TIMER = 600;//Seconds
//If using the RP XP option, decreasing the chat timer will mean that players
//will have to chat more often to recieve the XP reward.
const int CHAT_TIMER = 600;//Seconds

//Available AFK types:
//1 = Repeating floating text on player.
//2 = A visual effect will be applied to the player.
//3 = Transport player to an object in AFK area.
//4 = Boot player.
//5 = Play Animation(looping type only).
const int AFK_TYPE = 1;

//Options for AFK_TYPE 1:
//Enter message that you want to float over the players head when he/she is AFK.
//Default: "AFK"
const string AFK_FLOATING_MESSAGE = "AFK";
//Change the color of the floating text. Options for colors:
//STRING_COLOR_BLACK
//STRING_COLOR_BLUE
//STRING_COLOR_GREEN
//STRING_COLOR_PINK
//STRING_COLOR_RED
//STRING_COLOR_ROSE
//STRING_COLOR_WHITE
const string FLOATY_COLOR = STRING_COLOR_RED;
//Allow floaty text with all AFK types. Default: FALSE
const int FLOATY_TEXT_ALWAYS = FALSE;

//Option for AFK_TYPE 2:
//Enter desired VFX number or constant. Default: VFX_DUR_FLAG_GOLD
const int AFK_EFFECT = VFX_DUR_FLAG_GOLD;

//AFK OBJECT. This object is used for AFK_TYPE 2 and AFK_TYPE 3.
//Simply pick any placeable of your choosing and give it the tag below.
//Also make sure the object is checked "plot".If using the object for TYPE 2 you
//can put it in any area. If using it for TYPE 3 place it in the AFK area that
//players will be teleported to.
//Note for AFK_TYPE 3: This option sets a location on the player that they can
//be auto-ported back to. However should the player log out and log back in or
//if the server crashes, this location will be lost. Therefore you should have
//an alternate way of leaving the AKF area.
//Default: "GOGS_AFK_OBJECT"
const string AFK_OBJECT = "GOGS_AFK_OBJECT";
//Additional note for AFK type 3: I have made it so that a player who is in the
//AFK area must type something/anything in the chat bar for them to return to
//their stored location. This is to prevent other players from simply pushing
//the player around and causing a change in location which would teleport them.
//A repeating message is sent to the player until they type something.
//Message:
const string AFK_AREA_MESSAGE = "Type anything in the chat bar to be ported back to saved location.";
//Select color of message. Same color options as above apply.
const string AREA_MESSAGE_COLOR = STRING_COLOR_RED;

//Option for AFK_TYPE 5:
//Enter desired looping animation constant for the AFK animation.
//Default: ANIMATION_LOOPING_SIT_CROSS
const int AFK_ANIMATION = ANIMATION_LOOPING_SIT_CROSS;

//Send a message to the party members of the player that is AFK. This will
//display a message once when the player has gone AFK and once when the player
//is no longer AFK.
//If TRUE, message will be displayed to all party members. DEFAULT: TRUE
const int SEND_FACTION_MESSAGE = TRUE;
//Select color of message. Same color options as above apply.
const string FACTION_MESSAGE_COLOR = STRING_COLOR_PINK;

//Options for awarding RP XP. Basically, if the player is not AFK and has
//chatted within the last timer delay, the player will receive XP.
//Set to TRUE to give RP XP.
const int RP_XP_REWARD = FALSE;
//Set desired amount of XP to give every cycle.
const int XP_AMOUNT = 100;

////////////////////////////END CONFIGURABLE OPTIONS////////////////////////////

////////////////////////////////////////////////////////////////////////////////
void SendAFKFactionMessage(object oPC)
{
.............


Changing the constants in the beginning of the script will change how the script works below it. Thus acting as a kind of switch. And of course doing this allows for easy customization for other people who might use the script/system.


That's all well and good, but that's not what he was talking about. I believe I mentioned that constant should only be used for things that do not change, and are used constantly. If not, I meant to.

#37
GhostOfGod

GhostOfGod
  • Members
  • 863 messages

Redunct wrote...

That's all well and good, but that's not what he was talking about.


Actually that is what he has been talking about. There was just a bit of confusion about it.(either that or I am reconfused :lol:)
And of course using constants in this fashion does not make then no longer constant. They are still constant "in game" and can not be changed. They are just something that you can change in the toolset before running the game to alter the script. As the original OP was trying to get across was that this could be useful for template/reusable type scripts. Instead of having three or four scripts to change back and forth between while your messing around with stuff in the tool set, you can make 1 script with a const int at the top to switch which way/version of the one script you want to go with.

Again this would mainly be for multiple use systems and can help cut back the number of scripts used in certain situations.

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


#38
Redunct

Redunct
  • Members
  • 49 messages

GhostOfGod wrote...

Redunct wrote...

That's all well and good, but that's not what he was talking about.


Actually that is what he has been talking about. There was just a bit of confusion about it.(either that or I am reconfused :lol:)
And of course using constants in this fashion does not make then no longer constant. They are still constant "in game" and can not be changed. They are just something that you can change in the toolset before running the game to alter the script. As the original OP was trying to get across was that this could be useful for template/reusable type scripts. Instead of having three or four scripts to change back and forth between while your messing around with stuff in the tool set, you can make 1 script with a const int at the top to switch which way/version of the one script you want to go with.

Again this would mainly be for multiple use systems and can help cut back the number of scripts used in certain situations.


Well, his example was nothing like that.