WarCraft: Source

 

ReturnDict

Page history last edited by freddukes@... 1 yr ago

Return Dict

 


This command returns a value in a dictionary to a local variable. This command is an advanced command, and if you don't know anything about dictionarys, then I suggest you read up on this link.

 

The correct syntax is:

 

<variable> = wcs.Command(<userid>).ReturnDict(<'Key-Name'>)

 

  • Variable - A local variable where you wish to store the value
  • Userid - The users Dictionary that you will be accessing
  • Key name - The name of the key you want to retrieve the value from

 


 

Example:

 

def player_spawn(ev):

    player = wcs.Command(ev['userid'])

    player.UpdateDict('myloop',0)

    # Creates a new value, see UpdateDict

 

def player_ultimate_on(ev):

    myloop(ev['userid'])

    # Starts myloop, and passes the variable userid

 

def myloop(userid):

    # Here we are going to modify the dict to add 1 each time

    player = wcs.Command(userid)

    player.ModDict('myloop',1)

    # Adds 1 to the current value in the dictionary, see ModDict

    gamethread.delayedname(1,'current_loop',myloop,userid)

    # Repeat the loop 1 second later, with a name of current_loop

 

def player_ultimate_off(ev):

    gamethread.cancelDelayed('current_loop')

    # Cancel the current loop so it stops the looping process

    player = wcs.Command(ev['userid'])

    loop_counter = player.ReturnDict('myloop')

    # Returns the value inside the 'myloop'

    es.tell(ev['userid'],'#green','You held the ultimate key for %s seconds!'%loop_counter)

    # tells the user how many loops he did

Comments (0)

You don't have permission to comment on this page.