Using Variables/fr
|
[edit] Qu'est-ce qu'une "variable" et comment en créer une?Le terme exacte pour "créer" une variable est "déclarer" une variable. Une variable est soit un mot soit un nombre qui est "définis" par une valeur. Pour la plus part, codeurs/scripteurs essaient de donner un nom unique à la variable afin de la reconnaitre plus tard dans la création du code. [edit] EXEMPLE DE VARIABLESPour la santé d'un joueur : myplayer_health Prenez l'habitude de ne pas mettre d'espace à vos variables. Tous le monde vous le dira, PAS de variable avec des espaces. [edit] SyntaxVous devez vous demander : Qu'est-ce qu'une "syntax"? es_set <variable> <value>Note: Command parameters are described inside the
< and > characters. Optional parameters are contained within [ and ] characters.
es_xset <variable> <value>Note: Command parameters are described inside the
< and > characters. Optional parameters are contained within [ and ] characters.
As an example of the syntax above, let's say that we wanted to create a variable that holds my age. Let's call the variable that will hold my age: myage Let's say that I want the value of my age to be: 25 Here is how it would be coded: es_set myage 25 or using es_xset: es_xset myage 25 [edit] What is the difference between es_set and es_xset?[edit] es_setWhen you use "es_set", it will expand any variable that it finds. For example, if you want to set a variable for a player's health, then here is how it would be coded: es_set player_health event_var(es_userhealth) Another example: player name es_set player_name event_var(es_username) Once you have "declared" these variables, you can make use of them. They are now called "server variables". The shortened term for this is server var. For example, you can use the "es_msg" command to send this newly-coded information to the player chat area: es_msg server_var(player_name) has a health of: server_var(player_health) When the players see the message in the chat area, it will look like this (if the player name that you defined is "XE_ManUp"): Player Chat Message wrote: XE_ManUp has a health of: 75 [edit] es_xsetWhen you use "es_xset", it WILL NOT EXPAND any variable that it finds. (See es_x commands for more information.) For example, if we were to follow the above example for attempting (I will explain in a moment) to use "es_xset" to set the player's health and player's name to a variable: es_xset player_health event_var(es_userhealth) es_xset player_name event_var(es_username) Then, if we use the following code to display the above codes to chat: es_msg server_var(player_name) has a health of: server_var(player_health)
server_var(es_username) has a health of: server_var(es_userhealth) The above is bad code because with es_xset, no variables are expanded! If you want variables to be expanded, then use es_set.
[edit] Why use "es_xset" if it doesn't expand variables?Like the example of "myage" above, not every variable needs to be set to a value that needs expanded. A few good examples of "when" to use "es_xset" instead of "es_set":
[edit] Advanced NoteYou can (and should) use es_xset any time it is following an "if" statement. If es_xset is on the same line following the "if" statement, any variable found will be expanded. [edit] Good Example Code: (player_say.cfg)if (event_var(text) equalto "what's my name?") then es_xset player_name event_var(es_username) if (event_var(text) equalto "what's my name?") then es_xmsg Your name is: server_var(player_name) The above code will display this in player chat: Your name is: XE_ManUp
[edit] BAD Example Code: (player_say.cfg)es_xset player_name event_var(es_username) es_xmsg Your name is: server_var(player_name) The above code will display this in player chat: Your name is: server_var(player_name) [edit] What is the difference between es_set and es_setinfo?es_setinfo is depricated (older and no longer recommended). es_set performs the same function, but with the option to include a description of the variable. [edit] What is the difference between server_var and event_var?The underlying c++ code causes this requirement. When events are fired, they are passed as c++ objects. The variables germane to the event are retrieved from this object, unlike server variables. Thus, server_var retrieves a variable from the pool of all server variables, while event_var retrieves variables from the currently executing event. This helps keep excessive unnecessary-to-access event variables from cluttering the server variable namespace. (Is it possible to make your own events and event variables in event scripts?) [edit] Final NotesWhen you decide to declare a variable, make sure that if you are setting the variable with es_set, that the event you are using provides the information that you are trying to set. To test, you can simply use es_msg to display the information you are trying to set to a variable...like "event_var(es_username)". es_msg The username is: event_var(es_username) If the message displayed in player chat is: The username is: 0 then, you know that the particular event that you are trying to use does not give information about the player. As a quick "heads up", two events that will not give you ANY information about individual players are:
|
|
