bye
Forum
CS2D Scripts Script for doScript for do
18 Antworten 1
bye
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
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
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".
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
Dousea hat geschrieben
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
That's still going over my head.
Wouldn't variable 'boolean' return the text instead of a true boolean value? How does this work?
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.
But ya all forgot string.lower
1
message = message:lower()
Nekomata hat geschrieben
That's still going over my head.
Wouldn't variable 'boolean' return the text instead of a true boolean value? How does this work?
Dousea hat geschrieben
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
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".
Maybe shouldn't you post in Tricks in CS2D Scripting that you might not know.? Just asking.
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"
@ _Yank:
You have a typo in that example. You're opening 3 brackets and closing 4 brackets. Fixed version:
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")
3× editiert, zuletzt 04.01.16 03:38:49
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!
1