Code:class WipeCycle: def __init__(self): self.Title = "WypeCycle" self.Description = "This example illustrates how to use a basic configuration file" self.Author = "NoSharp" self.Version = V(1, 0, 0) def Init(self): command.AddChatCommand("WipeChangeNext", self.Plugin, "CWDN") command.AddChatCommand("WipeChangeLast", self.Plugin, "CWD") command.AddChatCommand("WipeInfo", self.Plugin, "W") def LoadDefaultConfig(self): self.Config = { "Date of the next wipe": "DATE", "Date of the last wipe": "DATE" } def CWD(self, player, cmd, args): #if args[0] != "/" or ".": # rust.SendChatMessage("sorry You have not included a date") #else: self.Config["Date of the last wipe"] = args[0] self.SaveConfig() rust.SendChatMessage(player, "you have successfully Changed the Date of last Wipe and is now " + self.Config["Date of the last wipe"]) rust.SendChatMessage(player, "The Date of the last Wipe is " + self.config["Date of the last wipe"] + "The Date of the Next wipe is " + self.config["Date of the next wipe"]) def CWDN(self, player, cmd, args): if args: if args[0] != "/" or "." or "\#" or "," or "|": self.Config["Date of the next wipe"] = args[0] self.SaveConfig() rust.SendChatMessage(player, "you have successfully Changed the Date of next Wipe and is now " + self.Config["Date of the next wipe"]) rust.SendChatMessage(player, "The Date of the last Wipe is " + self.config["Date of the last wipe"] + "The Date of the Next wipe is " + self.config["Date of the next wipe"]) else: rust.SendChatMessage("ERROR: PLEASE INPUT A VALID DATE") def W(self, player, cmd, args): rust.SendChatMessage(player, "The Last Wipe Was " + self.Config["Date of the last wipe"] + " The next Wipe is on " + self.Config["Date of the next wipe"])
How can i make this IF statement work?
Discussion in 'Rust Development' started by Serenity 3, Aug 2, 2016.
-
This will help: complex if statement in python
-
It won't, because that isn't the issue.
needs to beCode:args[0] != "/" or "." or "\#" or "," or "|"
this can be rewritten asCode:args[0] != "/" or args[0] != "." or args[0] != "\#" or args[0] != "," or args[0] != "|"
I still don't think that this is what he's trying to do, though.Code:not (args[0] == "/" and args[0] == "." and args[0] == "\#" and args[0] == "," and args[0] == "|")
The code above is the equivalent of the logical expression
"args[0] does not equal all of {/, ., #, ,, |}", which makes no sense, as args[0] can only be one of these, so the condition will always be true. -
thanks
-
You probably want the if block to be run either when args[0] is any of these characters or if args[0] isn't any of these characters.
In Python you can write this as
orCode:if args[0] in "/.\#,|":
accordingly, as long as you don't need to check for many characters (in that case you should use {"/", ".", "\#", ",", "|"} instead of "/.\#,|").Code:if args[0] not in "/.\#,|":
-
well it now returns with nothing on the Player text
-
I was pointing out that you need to compare it everytime, not just once.
-
That stackoverflow post is a question about syntactic sugar for range expressions, though.
-
I didn't read that far into it the nature of it, just wanted to give a pointer towards the correct syntax.
-
so i would be right to put:
if args:
if args[0] not in "/.\#,|":
rust.SendChatMessage("ERROR: PLEASE INPUT A VALID DATE")
else:
self.Config["Date of the next wipe"] = args[0]
self.SaveConfig()
rust.SendChatMessage(player, "you have successfully Changed the Date of next Wipe and is now " + self.Config["Date of the next wipe"] + "The Date of the last Wipe is " + self.config["Date of the last wipe"] + "The Date of the Next wipe is " + self.config["Date of the next wipe"]) -
Depends on what you're trying to do, I guess.
-
im trying to make it identify to the user has used a invalid term.
