+ Reply to Thread
Results 1 to 7 of 7

Thread: Issue with table key not a string

  1. #1
    Rift Chaser Ferather's Avatar
    Join Date
    Jun 2011
    Posts
    341

    Default Issue with table key not a string

    Hi

    I've been trying to add target and caster details to the Super Meter tooltip. Programming so far works but I am running into an unusual issue that prevents my output.

    After some debugging ive noticed that for some reason the key that was inserted is not a string.

    Sample Code:

    caster.targets[params.targetName] = 1

    Sometimes I get:

    ["Expert Boss Dummy"] = 2 , Which is a string.
    [Ferather] = 2 , Which is not a string.

    Can anyone explain why this happens?

    I've even tried tostring() which did not work.

    I've tried: local name = tostring(params.targetName) again did not work.

    All inputs are strings by default. I get no errors but no output.
    Last edited by Ferather; 08-02-2013 at 06:37 AM.

  2. #2
    Shield of Telara Adelea's Avatar
    Join Date
    Mar 2011
    Posts
    734

    Default

    What is the problem you are having?

    You only get the "'s around keys when they contain spaces.

    Code:
    local testtable = {
    ["Expert Boss Dummy"] = 2,
    ["Ferather"] = 2
    }
    dump(testtable)
    local k
    k = "Expert Boss Dummy"
    print(testtable[k])
    k = "Ferather"
    print(testtable[k])
    {["Export Boss Dummy"] = 2, Ferather = 2}
    2
    2
    http://forums.riftgame.com/image.php?type=sigpic&userid=125779&dateline=13553  38065

  3. #3
    Wym
    Wym is offline
    Shadowlander
    Join Date
    Jun 2012
    Posts
    25

    Default

    I assume you're talking about the saved variables files, in which your examples are parts of the variable initialization.

    Are you 100% sure your Ferather is in brackets? Because the following are equivalent:

    Variable = {}
    Variable["a"]=1


    or

    Variable = {
    a = 1
    }


    or

    Variable = {
    ["a"] = 1
    }


    or even

    Variable={}
    Variable.a=1



    But the blue ones don't work if the index (a) contains spaces (or anything else that isn't a word character). So, in the SavedVariables Lua files, Rift generates the blue version for indexes that are single words, and the green version in every other case, and there's nothing to worry about. So, if your debugging consists of "mark the variable to be persistent, then check the SavedVariables file for its contents", Rift's behaviour might just be misleading.

    Maybe you've been talking about something completely different, but in this case, it would help if you could be a bit more verbose about where you see the strange array index -- your code looks fine to me, and there shouldn't be a need for tostring at all.

  4. #4
    Rift Chaser Ferather's Avatar
    Join Date
    Jun 2011
    Posts
    341

    Default

    Well the main issue is, the data is built into a string which is called 'local extra = STRINGHERE'

    when I use print(extra) the string is correctly printed with correct data.

    Yet when I use 'extra' to output to a frame sometimes I get output, other times nothing appears even though the print command is displaying the string in the rift chat box.

    My original thought was that some of the keys where not strings, but thankfully you have corrected that.

    Code:
    if casters then
    	if not SuperMeter_pvp then
    		for k,v in pairs (casters) do
    			unitsTotal = unitsTotal + v
    			table.insert(units, k)
    		end
    		table.sort(units, function(a, b) return unit.casters[a] > unit.casters[b] end)
    	end
    end
    
    if targets then
    	if not SuperMeter_pvp then
    		for k,v in pairs (targets) do
    			unitsTotal = unitsTotal + v
    			table.insert(units, k)
    		end
    		table.sort(units, function(a, b) return unit.targets[a] > unit.targets[b] end)
    	end
    end
    
    if #units > 20 then
    	for i = 21, #units do
    		units[i] = nil
    	end
    end
    
    if not advanced and value > 0 then
    	local abilityValue = value
    	local extra = ""
    	
    	if mode == "DPS" or mode == "HPS" or mode == "OPS" then
    		abilityValue = SuperMeter.Number(value / time)
    	end
    	
    	if casters then
    		for k,v in pairs (units) do
    			extra = extra .. "[ " .. casters[v] .. " ] [ " .. string.format("%.2f%%", (casters[v] / unitsTotal) * 100) .. " ]  " .. v .. "\n"
    		end
    	end
    	
    	if targets then
    		for k,v in pairs (units) do
    			extra = extra .. "[ " .. targets[v] .. " ] [ " .. string.format("%.2f%%", (targets[v] / unitsTotal) * 100) .. " ]  " .. v .. "\n"
    		end
    	end
    	
    	data1 = data1 .. "\n" .. extra
    	info1 = info1 .. "[ " .. abilityValue .. " ] [ " .. string.format("%.2f%%", (value / total) * 100) .. " ]  " .. v .. " \n"
    	
    	run = true
    end
    when using: /script dump(Inspect.Unit.Detail("player")) the name entry has the "" around the name yet there are no spaces, which is why I thought there was a bug with the keys.

    Help needed
    Last edited by Ferather; 08-02-2013 at 08:32 AM.

  5. #5
    Shield of Telara Adelea's Avatar
    Join Date
    Mar 2011
    Posts
    734

    Default

    If extra is valid when you print it out after constructing it, but displays nothing later on (presumably when you use it in the context of data1 ?) - I would guess that at some point you are updating the value of data1 and losing any updates you may have made to it.

    Without seeing everything its hard to say much more.
    http://forums.riftgame.com/image.php?type=sigpic&userid=125779&dateline=13553  38065

  6. #6
    Rift Chaser Ferather's Avatar
    Join Date
    Jun 2011
    Posts
    341

    Default

    Hmm will take a look later, but just so you know, the print(extra) command was just before: data1 = data1 .. "\n" .. extra

    So:

    print(extra)
    data1 = data1 .. "\n" .. extra

    No other changes to data1 after this point, But I will check your idea.

  7. #7

+ Reply to Thread

Bookmarks

Posting Permissions

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