Page 1 of 1

Question regarding commands

Posted: Fri Jan 22, 2016 3:00 pm
by decompile
Hey,

I need your help since im not getting what I want.

I tried to add a !info <mapname> command, when its just !info it uses currentMap

Syntax: Select all

@SayCommand("!info")
@ClientCommand("sm_info")
def printInfoStats(command, index, team=None):
userid = userid_from_index(index)
if command.get_arg_count(): #0 if just !info
mapName = command.get_arg_string(0).lower()
if not validMap(mapName):
return tell(player.userid, "map_not_found", {"mapName": mapName})
else:
mapName = global_vars.map_name
#insert code xxx


Would this work? It seems the arg_count removes the !info command, but how can you actually get the first argument or the 2nd one etc.

Posted: Fri Jan 22, 2016 3:07 pm
by iPlayer
command.get_arg(0) ?
command[0] ?

Posted: Fri Jan 22, 2016 3:25 pm
by satoon101
Do you want the command or the 1st argument? The command is at index 0, the first argument is at index 1. I would probably use something like this:

Syntax: Select all

@SayCommand('!info')
def map_info(command, index, team_only):
if command.get_arg_count():
map_name = command[1]
else:
map_name = global_vars.map_name

Posted: Fri Jan 22, 2016 3:41 pm
by decompile
Realy weird

decompile : !info surf_the_gloaming
Print MapName: q@.

Posted: Mon Jan 25, 2016 3:30 pm
by satoon101
That seems really strange. I am not encountering that at all, and it works fine for my testing. The only issue I noticed when testing is that I forgot that the command is included in the count of command.get_arg_count(), so we need to check if there is more than 1:

Syntax: Select all

@SayCommand('!info')
def map_info(command, index, team_only):
if command.get_arg_count() > 1:
map_name = command[1]
else:
map_name = global_vars.map_name

print('MapName:', map_name)

Posted: Mon Jan 25, 2016 4:06 pm
by Ayuto
I talked to him about this issue via steam. He was passing the Command object to a thread. So, when the thread was using the object, the internal pointer was probably already deallocated, which resulted in reading invalid memory blocks. As a workaround I suggested to pass tuple(command) to the thread. This will create a tuple containing all arguments of the Command object.