#Attempt to index field 'displays' (a nil value)

44 messages · Page 1 of 1 (latest)

tacit cave
#

Lua error in aura 'ShareID_today': Custom Text Function
attempt to index field 'displays' (a nil value)
https://wago.io/km0L4LFvc

I'd like to fork and fix this weakaura. The code references something that does exist in the SavedVariables so I am lost as to why it's giving me a nil error as I thought this meant it didn't exist.

Simple WeakAura which allows to share your own ID's for everyone who PMs you. Available commands: !sharing !info F

static rampart
#

best is to ask author to rewrite the aura using aura_env.saved

tacit cave
#

That's probably not going to happen as it's not been updated since shadowlands, I will have a look at trying to do that myself.

static rampart
#

root of the issue come from trying to access WeakAurasSaved which is blocked now

#

correct way to save data within a wa is to save it in aura_env.saved

tacit cave
static rampart
#

start of on init's code type

aura_env.saved = aura_env.saved or {
  SharesToday = 0,
  SharesTotal = 0
}

then for example instead of
WeakAurasSaved["displays"]["ShareID"]["SharesToday"] = WeakAurasSaved["displays"]["ShareID"]["SharesToday"] + 1
use
aura_env.saved.SharesToday = aura_env.saved.SharesToday + 1

tacit cave
#

Yeah that was my assumption, I figured the dot must mean they are objects or object-like.

static rampart
#

tableName.fieldName is same as tableName["fieldName"]

#

["fieldName"] allows to use a variable name local someField = "fieldName"; local a = tableName[someField]

tacit cave
#

Ah gotcha, useful information thank you!

#

hmmm I am still getting the same error just for saved instead.

attempt to index field 'saved' (a nil value)

tacit cave
#

I did yes

static rampart
#

can you paste full error?

tacit cave
#

it keeps updating every frame so it's hard to copy and paste out of the bugsack

static rampart
#

why would it update every frame?

#

seems wrong

#

it should update when trigger update, with according trigger

tacit cave
#

Yeah I never wrote this, just trying to fix it.

I need to rewrite the trigger so it only updates every 30 seconds, that was the next thing I was going to change.

static rampart
#

it's not the same aura

#

you can't read aura_env.* from an other aura

tacit cave
static rampart
#

ShareID and ShareID_today are 2 different auras

tacit cave
#

right so what would I have to do then?

#

move the init from SharedID to each aura

static rampart
#

it's too complicated to fix properly

#

have to rewrite from scratch

#

and i don't know what this is counting

tacit cave
#

It's a weakaura that shares lockouts.

So someone whispers the character a keyword, it auto invites them to a group, they enter the instance and the character that invited them leaves after 30 seconds and counts how many lockouts it's for the sessions, today and total shares.

static rampart
#

problem with this aura, is author doesn't know the basics of weakauras 😦

tacit cave
#

Yeah the author mentioned that in the description, they said it was their first attempt at lua.

static rampart
#

trigger collect data, update when data has change, and display tab use data from trigger
here it use always active triggers, and a custom text function reading a global variable every frames

tacit cave
#

Yes I noticed that.

static rampart
#

proper solution is to have the main aura that collect data write in aura_env.saved and use

#

!scanevents

static rampart
#

to notice other auras that there is an update, with the data as 1st arg

#

for example in 1st aura instead of

    elseif event == "GROUP_LEFT" then
        
        aura_env.IsInvitedForSharing = false
        aura_env.CurrentCharInGroup = ""
        aura_env.CurrZoneID = ""
        aura_env.CurrZoneName = ""
        aura_env.MaxTime = ""
        aura_env.CurrTime = ""
        aura_env.CharIsReady = false
        
    end

do

    elseif event == "GROUP_LEFT" then
        aura_env.saved.IsInvitedForSharing = false
        aura_env.saved.CurrentCharInGroup = ""
        aura_env.saved.CurrZoneID = ""
        aura_env.saved.CurrZoneName = ""
        aura_env.saved.MaxTime = ""
        aura_env.saved.CurrTime = ""
        aura_env.saved.CharIsReady = false
        WeakAuras.ScanEvents("update_shareid", aura_env.saved)
    end

then replace trigger1 from shareid_today with a TSU listening to event update_shareid with function

function(states, event, data)
  if event == "update_shareid" and data then
    states[""] = { show = true, changed = true }
    for k, v in pairs(data) do
      states[""][k] = v
    end
    return true
  end
end

then in display you can use as text replacemnt %CurrZoneName or in a custom text aura_env.state.CurrZoneName

#

it's about as far as i can go without rewriting the aura myself