Results 1 to 6 of 6

Thread: Loop target.name with a list

  1. #1
    iBot User
    Join Date
    Sep 2012
    Posts
    239
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    46 Post(s)
    Reputation
    23
    Rep Power
    5

    Loop target.name with a list

    This:

    PHP Code:
    monsters = {"Rat","Bug","Bat"}

    if 
    target.name == monsters then
    ...action
    end 
    Doesn't work because target.name doesn't accept array. How do I loop a list with it?

  2. #2
    Normal User mattos123's Avatar
    Join Date
    Sep 2012
    Location
    Brasil
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    12
    Rep Power
    5
    best option for this case would be ,
    separated action for each monster,
    local mob1 = "MOB1nick"
    local mob2 = "MOB2nick"

    while (target.name == mob1) then
    do action
    end

    while(target.name == mob2) then
    do action
    end
    Se ontem fosse anti-ontem, e hoje fosse ontem, hoje seria oque ?





    ~O amanhã


  3. #3
    Normal User
    Join Date
    Jun 2012
    Location
    Sweden
    Posts
    1,671
    Mentioned
    18 Post(s)
    Tagged
    1 Thread(s)
    Quoted
    8 Post(s)
    Reputation
    132
    Rep Power
    9
    Lua Code:
     
    local CREATURES = {"monster","monster2"}
     
    for C = 1, #CREATURES do
        if target.name == CREATURES[C] then
            --
        end
    end
    Last edited by Furieri; 06-26-2015 at 10:36 PM.

  4. #4
    iBot User
    Join Date
    Sep 2012
    Posts
    239
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    46 Post(s)
    Reputation
    23
    Rep Power
    5
    @mattos123
    But this is the whole point of using a loop: to avoid huge lines of code.

    @soder
    Thanks, that's what I was searching

  5. #5
    iBot User Raph_'s Avatar
    Join Date
    Feb 2013
    Posts
    391
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    59
    Rep Power
    4
    You can use also table.find() if you want, like:
    local m = {"demon", "ferumbras"}

    if table.find(m, target.name) then
    --
    end

  6. #6
    iBot User
    Join Date
    Sep 2012
    Posts
    239
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    46 Post(s)
    Reputation
    23
    Rep Power
    5
    Btw, how can I do this:

    PHP Code:
        for 1#SELLABLES_LIST do
            
    setsettings("Settings\\Looting\\List\\ . SELLABLES_LIST[D] . \\Destination""01")
        
    end 
    I don't remember to put that inside a string.

    EDIT:

    Got it working
    PHP Code:
        for 1#SELLABLES_LIST do
            
    setsettings("Settings\\Looting\\List\\" .. SELLABLES_LIST[D] .. "\\Destination""01")
        
    end 
    Last edited by john86; 04-24-2013 at 11:05 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •