Script for do
18 replies



02.01.16 03:34:32 pm
hi,how to make if say "!off" then i false , if say "!on" then it true ._., i want all helps cause i'm creating script
bye

bye
Multiple account of Ya_Bogalb (a.k.a TN Anonymous)
Code:
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
function say_(id, text)
if string.sub(text,1,4) == "!off" then
-- Do something
return false
elseif string.sub(text,1,3) == "!on" then
-- Do something
return true
end
end
if string.sub(text,1,4) == "!off" then
-- Do something
return false
elseif string.sub(text,1,3) == "!on" then
-- Do something
return true
end
end
However, it's advisable to explain what exactly do you want because nobody understands what do you mean by "if i !on then it's true" and such. Here I gave you a code but I am still in doubt what do you want precisely though.
Code:
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
addhook("say","_s")
function _s(id,t)
if t == "!off" then
bool = false
elseif t == "!on" then
bool = true
end
end
function _s(id,t)
if t == "!off" then
bool = false
elseif t == "!on" then
bool = true
end
end
He didn't want to explain it but it's enough of an explanation. He wants to be able to control something by saying "on/off".
Will do pretty much the same as
GeoB99's and
Rainoth's.


Code:
1
2
3
4
5
6
7
2
3
4
5
6
7
addhook("say", "sayhook")
function sayhook(id, message)
if (message == "!off" or message == "!on") then
boolean = message == "!on"
end
end
function sayhook(id, message)
if (message == "!off" or message == "!on") then
boolean = message == "!on"
end
end
I'm awesome ... and I really like cookies.
@
Dousea: Ooooh. I was aware of a similar method for writing an IF but not like how you did. You're incorporating an 'if' while assigning a value to 'boolean'. Daaam. I learned sth new today.


Code:
1
2
3
4
5
6
7
2
3
4
5
6
7
addhook("say", "sayhook")
function sayhook(id, message)
if (message == "!off" or message == "!on") then
boolean = message == "!on"
end
end
function sayhook(id, message)
if (message == "!off" or message == "!on") then
boolean = message == "!on"
end
end
That's still going over my head.

Wouldn't variable 'boolean' return the text instead of a true boolean value? How does this work?

@
Nekomata: well, he's comparing the message just like you do in an if. An if always returns either 'true' or 'false' values (not in text of course) and then he assigns the boolean to be the result of the if


Ah, I sort of get it now. Also that
Either I'm missing out something really simple minded (I tend to do that) or I need to hit the basics of conditions.
Nevertheless, til here as well. Time to rewrite parts of my scripts and to hit the reference & docs.
Code:
sets "!on" as true from the two values. But I'm still not sure how that is working code-wise and behind the scenes.1
boolean = message == "!on"
Either I'm missing out something really simple minded (I tend to do that) or I need to hit the basics of conditions.

Nevertheless, til here as well. Time to rewrite parts of my scripts and to hit the reference & docs.

@
Nekomata: Well message must be either "!on" or "!off" because of message == "!off" or message == "!on" condition. boolean must be the value of message == "!on" comparison. boolean must be either true or false based on the comparison.

I'm awesome ... and I really like cookies.
@
VADemon: Are you praising or insulting
? About the string.lower, put it under line 3.


Code:
1
message = message:lower()
I'm awesome ... and I really like cookies.


Code:
1
2
3
4
5
6
7
2
3
4
5
6
7
addhook("say", "sayhook")
function sayhook(id, message)
if (message == "!off" or message == "!on") then
boolean = message == "!on"
end
end
function sayhook(id, message)
if (message == "!off" or message == "!on") then
boolean = message == "!on"
end
end
That's still going over my head.

Wouldn't variable 'boolean' return the text instead of a true boolean value? How does this work?

LUA - Precedence
I would use parenthesis just to make it clearer tho.
(message == "!on") as a condition, returns true or false, which is a boolean value. Then the condition's result is assigned to a variable. In this case the variable's name is "boolean".
@
Dousea: Oh, wow that's something new for me. Though I haven't learn many things in Lua, this trick actually intrigued me. 
Maybe shouldn't you post in
Tricks in CS2D Scripting that you might not know.? Just asking.


Maybe shouldn't you post in


@
GeoB99: I thought everyone knows it. It just uses logic.

I'm awesome ... and I really like cookies.
You can use this various ways
Code:
1
2
2
print((type({1,2,3}) == "string") and "this is a string") or "this is not a string" ) -- Prints "this is not a string"
print((type("Hello") == "string") and "this is a string") or "this is not a string" ) -- Prints "this is a string"
print((type("Hello") == "string") and "this is a string") or "this is not a string" ) -- Prints "this is a string"
Expressions (x == y) are either true or false. You can set variables via expressions and you can also return the result of an expression. I'm surprised that this many people didn't know that even though it's the basics of how the if statements work.
@
_Yank:
You have a typo in that example. You're opening 3 brackets and closing 4 brackets. Fixed version:
@

You have a typo in that example. You're opening 3 brackets and closing 4 brackets. Fixed version:
Code:
1
2
2
print(type({1, 2, 3}) == "string" and "this is a string" or "this is not a string")
print(type("string") == "string" and "this is a string" or "this is not a string")
print(type("string") == "string" and "this is a string" or "this is not a string")
edited 3×, last 04.01.16 03:38:49 am
A thousand may fall at your side, ten thousand at your right hand, but it will not come near you. You will only look with your eyes and see the recompense of the wicked. - Psalm 91:7-8 ESV
Just an addition, you can't concatenate the expression with other strings without brackets.
Well I guess we're off-topic so it better ends now.
Code:
1
2
2
print("This is " .. type("") == "string" and "" or "not" .. " a string!") -- Wrong!
print("This is " .. (type("") == "string" and "" or "not") .. " a string!") -- Right!
print("This is " .. (type("") == "string" and "" or "not") .. " a string!") -- Right!
Well I guess we're off-topic so it better ends now.
I'm awesome ... and I really like cookies.



