Team Spartan Cookies & Milk Forums
Creating sound for multivalue table fails - Printable Version

+- Team Spartan Cookies & Milk Forums (https://teamscm.co.uk)
+-- Forum: Garry's Mod (https://teamscm.co.uk/forum-4.html)
+--- Forum: Starfall (https://teamscm.co.uk/forum-7.html)
+--- Thread: Creating sound for multivalue table fails (/thread-2861.html)



Creating sound for multivalue table fails - Captain Krisu - 29-10-2018

Just a general question/help request, since I can't seem to find solution myself.

I'm trying to do a multivalue table where I store my sounds, with their paths for getting sound durations easier and creating them easier.. except the latter won't work.

Error: attempt to call field 'create' (a nil value)

Code:
local chip = ents.self() local sounds = { ["alert"] = { path = "st/misc/abandon_ship.wav", snd = nil } for k,v in pairs(sounds) do print(tostring(v) .. ", " .. tostring(v.snd)) -- Debugging stuff, had to check if stuff was correct, it is v.snd = sounds.create(chip, v.path) end

I've tried using key instead of straight value, ipairs, nothing worked.


RE: Creating sound for multivalue table fails - Salira - 29-10-2018


local sounds = {
alert = { path = "st/misc/abandon_ship.wav", snd = nil }
}

This should be the correct formatting. Let me know if this still doesn't work.
Read from sounds.alert.path for the path of the sound.


RE: Creating sound for multivalue table fails - Person8880 - 29-10-2018

Here is the problem:
local sounds = {
You've created a local variable called sounds, then later are trying to use the global sounds table. You'll need to rename your local variable so it doesn't clash.


RE: Creating sound for multivalue table fails - Captain Krisu - 29-10-2018

(29-10-2018, 08:21 PM)Person8880 Wrote: Here is the problem:
local sounds = {
You've created a local variable called sounds, then later are trying to use the global sounds table. You'll need to rename your local variable so it doesn't clash.

Oh heck

[Image: 1*YZyHx8ZittvvirTTlwffxQ.gif]

I'm an idiot Big Grin