ET-Scripts
Welcome to the ET-Scripts website.
Enter your username and password to login.

Greetings,
Chef
ET-Scripts
Welcome to the ET-Scripts website.
Enter your username and password to login.

Greetings,
Chef
ET-Scripts
Would you like to react to this message? Create an account in a few clicks or log in to continue.

ET-Scripts

For all your Scripts and Configs.
 
HomeLatest imagesSearchRegisterLog in

 

 Chef's Guide - Config making (5) "Toggle"

Go down 
AuthorMessage
Chef
ET-Scripts Founder
ET-Scripts Founder



Posts : 34
Join date : 2009-03-27

Chef's Guide - Config making (5) "Toggle" Empty
PostSubject: Chef's Guide - Config making (5) "Toggle"   Chef's Guide - Config making (5) "Toggle" I_icon_minitime3/27/2009, 23:32

Hey all,


It is me again, this time presenting my sixth GUIDE about Config making
Today we are going to talk about making a "toggler"
I think it is best if I explain what it is with an example.
Lets say I use the name #Chef* when I am not playing on one of the |FBI|Servers.
But I want to use the name |FBI|Chef|AAT| when I am on one of the |FBI|Servers.
I would like a simple way to change names.

This can be done with a toggler.
I can change name with one press of a button.
But it can be used on more things than a name.
For example, I can use it to toggle between 90 FOV and 110 FOV.
Or to toggle between 1.5 Gamma and 2.1 Gamma.
It is very easy with a toggler.
But making one is a little harder.

This is a script where we need to use the things we learned in GUIDE number 4 (Variables and vstr).

Okay, now lets start off with setting(storing) the names to variables.
Do this by making a cfg with the following in it(i suggest typing it, not using copy-paste because typing will make you learn better ):
Code:
Set name1 "set name Chef"
Set name2 "set name |FBI|Chef|AAT|"

This gives us two names to swich between.
Variable name1 and variable name2.
Now ofcourse we want to change name with only using one button.
Lets take the button P for example.
Our goal is to press P once and get name1.
Press it twice and get name2.
After pressing it three times we want name1 again.
So it is like somekind of loop.

Now it is not as easy as doing:
Code:
bind P "vstr name1"

To make it work like we want it to work we need another variable.
Lets call this one "namechange"

We want it to alternate between name1 and name2.
This can be done by doing the following:
Code:
Set name1 "set name Chef; set namechange vstr name2"
Set name2 "set name |FBI|Chef|AAT|; set namechange vstr name1"
Bind P "vstr namechange"
Set namechange "vstr name1"

We need the ; to seperate the commands, if you do not use the ; to seperate them ET sees them as one command and your cfg fails
We added
Code:
set namechange vstr name2
to the first line to make it activate the next line when we hit P(and our name changes to Chef).
That means if we hit P the next time we hit P our gets changed to |FBI|Chef|AAT|
And to do the same with the second line we added
Code:
set namechange vstr name1

Conclusion: If you look at this construction you will see that when name1 is executed, the variable namechange is then binded to the variable name2 because we added
Code:
set namechange vstr name2
That means the next time P is pressed and namechange is executed, it will no longer execute name1, but will now execute name2. The same thing goes for variable name2. When this variable is executed, the variable namechange is binded to name1 again.

Next thing, we are going to add another line to our cfg. That line will be:
Code:
set nameChanger "vstr name1"
This line can be seen as an initial value. Without this line the script would not know with which variable it should start the first time we press P. With this line we tell the script, that it should execute name1 the first time we press P.
So our final cfg should look like the following:
Code:
Set name1 "set name Chef; set namechange vstr name2"
Set name2 "set name |FBI|Chef|AAT|; set namechange vstr name1"
Bind P "vstr namechange"
Set namechange "vstr name1"
Vstr name1

So if you look at the construction of a toggle in general, it should always look like this:
Code:
set variable1 "command1; command2; ...; set mainVariable vstr variable2"
set variable2 "command1; command2; ...; set mainVariable vstr variable1"
bind key "vstr mainVariable"
set mainVariable "vstr variable1"
vstr variable1


Of course you can work with more variables than 2. With 3 variables it would look like this:
Code:
set variable1 "command1; command2; ...; set mainVariable vstr variable2"
set variable2 "command1; command2; ...; set mainVariable vstr variable2"
set variable3 "command1; command2; ...; set mainVariable vstr variable3"
bind key "vstr mainVariable"
set mainVariable "vstr variable1"
vstr variable1


So you can make the toggle with any amount of variables you want.



Well, I think this was certainly the hardest one yet(probably harder ones to come for the pro's among us )

Hope you understand it, if you did not do not be shy and ask me for help (please do not PM but post your question here)

Greetings,
Cheffie

PS: I made multiple GUIDES for cfg making, to follow them in the correct order check the (number) in the topic title

Spoiler:
Back to top Go down
http://et-scripts.omgforum.net
 
Chef's Guide - Config making (5) "Toggle"
Back to top 
Page 1 of 1
 Similar topics
-
» Chef's Guide - Config making (3) "Extra Information"
» Chef's Guide - Config making (4) "Variable & Vstr"
» Chef's Guide - Config making (6) "Echo"
» Chef's Guide - Config making (7) "+Vstr"
» Chef's Guide - Config making (1) "The Basics"

Permissions in this forum:You cannot reply to topics in this forum
ET-Scripts :: ET-Scripts :: Guides-
Jump to: