Page 9 of 9 FirstFirst ... 7 8 9
Results 81 to 89 of 89

Thread: Newbie has problems.

  1. #81
    Basic Member
    Join Date
    May 2014
    Posts
    270
    Quote Originally Posted by Yavimaya View Post
    reading over it quickly that is absolutely perfect man! thank you so much.

    while you are around, do you remember who you got the current itembuild scripts from? the format using the ItemUtility.lua.
    i am missing the author for my credit file.
    I modified Furiouspuppy's ItemData.lua by adding some functions, change some item names that don't return anything when you do GetItemComponents(item_name) such as item_eye_of_skadi, item_drums_of_endurance, item_euls, item_linken_sphere and soon, and add new item name.

  2. #82
    Basic Member
    Join Date
    Oct 2016
    Posts
    247
    thanks, i had forgotten who made the original, because although i had seen it i didnt move over to that format until you did as i didnt understand any of it back then.

  3. #83
    Basic Member
    Join Date
    Oct 2016
    Posts
    247
    Quote Originally Posted by The Nomad View Post
    No, no, you misunderstood
    The problem was not that your request wasn't clear. The problem was that there were many errors in the code that didn't make sense and I pointed them out. If you had fixed them, it might have worked closer to what you wanted
    Notice for instance, how arz iterates hero_roles using pairs, instead of i. There is a reason: the table is a dictionary, not an array. Notice how he doesn't use the # operator on hero_roles. I had a talk with him regarding the misconception and misusage some attribute it (same with table.getn, which does the same thing as #).

    i had tried using pairs, i never come and ask for help after only having one or 4 attempts.
    i usually try every way i can think of, sometimes i am totally off the mark, sometimes, like this time i did have a script before that was close, but not good enough, every time i used pairs i couldnt use [ ] because i had something else wrong, i just posted up the only thing i could get working in any way that gave me something to print and didnt have errors.
    i know i shouldnt have had things like the quotations around hero_roles, etc.... but it worked and without it it didnt work, so i used it.

  4. #84
    Basic Member
    Join Date
    Mar 2012
    Posts
    2,012
    OK But I can't believe that it didn't have errors. Every point I mentioned there is a violation of Lua syntax and should cause an error.
    The only reason why it wouldn't is because it didn't iterate anything. Anyway, glad you got your solution.
    Explanations on the normal, high and very high brackets in replays: here, here & here
    Why maphacks won't work in D2: here

  5. #85
    Basic Member
    Join Date
    Oct 2016
    Posts
    247
    it did, but all it did in the end was spew out index numbers.

    but thats ok, all i needed to know from Arz was how to run through the table, as i said i had tried x.[hero_roles] , [hero_roles], #X[hero_roles], etc etc, under pairs, ipairs, and for i = 1,... etc. all gave errors or crashed the game, what i posted was the only version i had that didnt and actually ran through one table atleast.
    i was also surprised #"hero_roles" worked, but i just thought that is how the table is named.... kind of like GXC's ward script, he also does similar, which may look like it shouldnt work to you? local beginningDireWardPoint = XYZ["beginningDireWardPoint"];


    im a slow learner with maths (and it seems programming, ive never been too slow with other technical stuff), you can give me an example, teach me how it works, change the numbers and im back to square one, i tend to just copy/paste stuff together.... or i am writing much more these days, but i still cant just write nice working scripts from scratch unless its doing stuff i have done before and not too hard.
    i just blunder my way through using examples of how others have done things if i need to work it out myself, sometimes its gonna just be completely wrong.
    Last edited by Yavimaya; 11-26-2017 at 02:55 PM.

  6. #86
    Basic Member
    Join Date
    May 2014
    Posts
    270
    #"hero_roles" will work but it won't give you the correct data you wanted. It'll count the length of string "hero_roles" so it'll give you 10 instead of the length of X["hero_roles"]. x.[hero_roles] is almost correct it should be X["hero_roles"] or X.hero_roles , [hero_roles] => you wont get anything from this instead of error, I think, #X[hero_roles] should be #X["hero_roles"] but it'll return 0 since it's a dictionary not an array. Since X["hero_roles"] or X.hero_roles will always the same for all heroes all you need to do is to fill the hero_name dictionary key X["hero_roles"][hero_name] to get the pair of key and value which in this case are the key => string role ("carry", "support", etc) and the value => int (0, 2, etc) related to the hero.

    This is how you loop through X["hero_roles"]
    Code:
    for key, value in pairs(X['hero_roles']) do
            --key will be the hero's name.
            --value will be the table of pair role and its value.
    	print(key..":"..tostring(value));
    end
    or
    Code:
    for key, value in pairs(X.hero_roles) do
            --key will be the hero's name.
            --value will be the table of pair role and its value.
    	print(key..":"..tostring(value));
    end
    and this is how to loop through X["hero_roles"] and print each hero role and role's value
    Code:
    for sHero, tRole in pairs(X.hero_roles) do
            --sHero is string hero's name
            --tRole is table role and its value for related hero
    	print(sHero)
    	for sRole, nVal in pairs(tRole) do
                    --sRole is string role ("carry", "support", etc)
                    --nVal is role's value (0, 1, etc)
    		print(sRole..":"..tostring(nVal))
    	end
    end
    Last edited by arz_on4dt; 11-26-2017 at 10:29 PM.

  7. #87
    Basic Member
    Join Date
    Dec 2016
    Posts
    731
    @arz_on4dt - everything in LUA is a dictionary. #["hero_roles"] probably returns 0 because the # operator only counts entries in the dictionary that are indexed numerically.

    Try this:
    Code:
    X = {
        1, 2, 3, 
        ['a'] = 3,
        'b',
        }
    
    print(#X)
    The print will return 4, because it doesn't count the ['a'] entry since it is not numerical.

    Furthermore, they have to be in sequence to count as well so:
    Code:
    X = {
        [1] = 1, [2] = 2, [3] = 3,
        ['a'] = 3,
        [9] = 'b',
        }
    
    print(#X)
    Will return 3, not 4, since the ['a'] doesn't count, and the [9] is not in sequence. (if you change [9] to [4] it will return 4).
    Last edited by nostrademous; 11-26-2017 at 10:59 PM.

  8. #88
    Basic Member
    Join Date
    Oct 2016
    Posts
    247
    thanks Arz, those last snippets of code with the explanation make it pretty much crystal clear how it works now.
    but ill probably have to reference them again next time i want to use it anyway, lol. :sad:

  9. #89
    Basic Member
    Join Date
    May 2014
    Posts
    270
    @nostrademous
    Yep, that's what I mean "sequenced numeric index dictionary". It's similar to array on how they declared, isn't it? That's why I just call it an array . In C it declared like this
    Code:
    int foo [5] = { 10, 11, 12, 13, 14 };
    and access the value by doing this
    Code:
    cout << foo[2]
    
    Result >> 12
    In Lua
    Code:
    local value = { 10, 11, 12, 13, 14 };
    and access the value by doing this
    Code:
    print(tostring(value[3]))
    
    Result >> 12

Posting Permissions

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