DIR Return Create A Forum - Home
---------------------------------------------------------
The Ultimate Knifing Clan Forum
HTML https://tukcforum.createaforum.com
---------------------------------------------------------
*****************************************************
DIR Return to: Add-on Help
*****************************************************
#Post#: 3016--------------------------------------------------
~:|Basic variable and string editing tutorial|:~
DIR By: Wrapperup
Date: May 30, 2012, 2:25 pm
---------------------------------------------------------
~:|Basic variable and string editing tutorial|:~
Hello, Welcome to my tutorial on Variables and String Editing!
_______________________________________
PHASE 1: VARIABLES
-----------------------------------------
Hello sir, I am going to teach you how to create, edit, and use
variables.
Lets start basic.
Lets say you want the console to say something like: "Hello sir,
This is a long message, so i will shorten it using a variable!".
Now, Lets stuff that puppy into a variable.
But before we do that, Lets explain a Global variable and a
Local variable.
A Global Variable ($) is defined by putting a $ infront of your
variable. These types of variables can be used by ANY Script /
code.
This can be useful for communicating with many different
scripts.
Example of a Predefined global var is $pref::server::name (Shows
name of server.).
A Local variable (%) is defined by putting a % infront of the
variable name. These types of vars are only used inside the
script it was created in.
An example could be a %client inside a script (NOTE: the client
var is usualy %client, It can be anything, but used it for the
tutorial.).
Now, lets stuff this puppy into a variable!
We will use a GLOBAL Variable.
this is how:
--- Code ---
$varname = "Hello sir, This is a long message, so i will
shorten it using a variable!";
--- End Code ---
Now, you are probably saying "But the console didn't say
anything, What now?".
What we did was CREATE a variable. The variable $varname is now
what is after the equal sign.
So, lets use it to make the console speak!
To do so, just put in:
--- Code ---
talk($varname);
--- End Code ---
It will make the console say whatever $varname is defined to
(Which is "Hello sir, This is a long message, so i will shorten
it using a variable!")
PHASE 2: CALCULATIONS USING VARIABLES
-----------------------------------------
Now, you probably want to do math using variables. You can use
Operators to calculate.
Lets say you want to add 2 and 2 together.
--- Code ---
$four = 2 + 2;
--- End Code ---
The code above will add 2 and 2 and set the variable "$four" to
what 2 + 2 equals, which is 4.
also, this can be done aswell
--- Code ---
$randomnum = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 50
--- End Code ---
OPERATIONS (That I can remember):
+ addition
- subtraction
/ division
* multiplication
^ to the power of (may not work)
< less than
> greater than
= equals to
$= if it equals to
PHASE 3: EDITING STRINGS USING FUNCTIONS
---------------------------------------------------------------------------------------------
Welcome to Phase 3! I am going to show you how to edit strings
using functions found with Torque.
You know how in most evals, you need a certain symbol infront of
your message to evaluate it?
Commonly $
It was used using getSubStr();
Lets say you want to get the first letter from the variable, you
would do this
--- Code ---
$editme = "Set the variable $blah with the S from this
variable!";
$blah = getSubStr($editme,0,1);
--- End Code ---
If you pay attention, getSubStr is used to get character(s) from
a variable, using the range.
The first one, the 0 from the code, shows where to start,0 means
from the start, so were starting from the start of the string.
The 1 in the variable tells how many characters far to go to get
to the desination.
It sets the variable to whatever is inbetween the range.
$blah equals S.
Next!
The next one is strReplace();
--- Code ---
$editme = "Change the DERP to something else in the code!
$edited = strReplace($editme,"DERP","REPLACED!");"
--- End Code ---
$edited now equals Change the REPLACED! to something else in the
code!
How its used:
--- Code ---
strReplaced(VARIABLE,"message to replace","Word to replace
with");
--- End Code ---
To count the number of words inside a string, Do this:
--- Code ---
$numberofletters = strLen(VARIABLE);
--- End Code ---
$numberofletters will equal to the count of how many characters
are in the string.
PHASE 4: USING IF()'S TO DETECT VARIABLE VALUE
Hello again! this is the last phase of the tutorial.
using an if() to detect when a variable = to what is destined or
1.
To detect when a variable = 5, do this
--- Code ---
if(VARIABLE $= 5)
--- End Code ---
If you want to detect when it is true,
--- Code ---
if(VARIABLE)
--- End Code ---
That detects if a variable = 1
If you want it to detect when it is NOT 1 or if it doesn't equal
what is destined
--- Code ---
if(!VARIABLE)
--- End Code ---
notice the ! in front of the variable, This means if it does
NOT.
! = NOT
This concludes the tutorial, Hope this helped you alot in using
variables
See ya!
#Post#: 3029--------------------------------------------------
Re: ~:|Basic variable and string editing tutorial|:~
DIR By: Wrapperup
Date: May 30, 2012, 8:02 pm
---------------------------------------------------------
Would this be worthy of a sticky? :o
*****************************************************
Page 1 of 1