lua,garrys-mod , Lua attempt to call field 'PlayFile' (a nil value)


Lua attempt to call field 'PlayFile' (a nil value)

Question:

Tag: lua,garrys-mod

I am trying to create an Lua addon for Garry's Mod but I keep coming across an error in my code. This is my code:

function say (Player, text, ent)
    s = "/misc/custom/"..text
    s2 = s..".mp3"
    sound.PlayFile(s2)
end
hook.Add("PlayerSay", "Say", say)

And this is the resulting error.

[saysoundtest25] lua/autorun/chatsounds.lua:4: attempt to call field 'PlayFile' (a nil value)
1. v - lua/autorun/chatsounds.lua:4
2. unknown - lua/includes/modules/hook.lua:84

Any ideas?


Answer:

User Robotboy655 on Facepunch helped me solve this! The final code:

hook.Add( "PlayerSay", "Say", function( ply, text, team )
BroadcastLua( 'surface.PlaySound("misc/custom/' .. text .. '.mp3")' )
end )

Thanks everyone for the help!


Related:


Lua C++ Table Iteration


c++,lua
I am having a slight confusion of how lua_next really works. User defines a table: a={["a1"]=20,["a2"]=30} I want to print this table with a C++ code: inline int lua_print(lua_State* L) { wxString wxReturnStr=wxEmptyString; wxString tempString=wxEmptyString; int nargs = lua_gettop(L); for (int i=1; i <= nargs; i++) { int type =...

Lua search through table


lua,corona,lua-table
I am working on a game project using Corona SDK and I am running into an issue. I am trying to use string.find() in a for loop to test to determine if a value is in a certain table and if so, add that value to another table. My problem...

How I get the cdata out in c function with variable arguments using luajit?


c++,c,windows,lua,luajit
Here is the code. The aim is to print messages. In PrintC, I would like to get e...but arrives as cdata. How can I unpack that or circumvent that? extern "C" { static int PrintC ( lua_State *L ) { // does not work cdata //executor* e = ( executor*...

Lua in-place initialized table order


c++,lua
I want to be able to do the following: MyObject:SetSize( { 10.0, 20.0 } ) But when I iterate over this on the C-side (SetSize is a C function). The order of the parameters is random. This is the C++ side processing the table: glm::vec2 State::PopVec2() { glm::vec2 v(); lua_pushnil(...

How can I convert a character code to a string character in Lua?


string,lua
How can I convert a character code to a string character in Lua? E.g. d = 48 -- this is what I want str_d = "0" ...

Lua obfuscator, how to


lua
I understand this question will appear silly but I'm clueless what to do, which makes it even more silly. I have written a lua script for a game - which works, but I've never actually run any lua with the lua programs(from the site download). I would like to obfuscate...

Supporting “recursive objects” in lua


class,lua
I'm fairly new to lua and have the following problem with an assignment from a class: We currently extend lua to support objects and inheritance. The Syntax for that is Class{'MyClass', attribute1 = String, attribute2 = Number } Class{'MySubClass', MyClass, attribute3 = Number } This works perfectly fine. The real...

Torch Lua: Why is my gradient descent not optimizing the error?


lua,neural-network,backpropagation,training-data,torch
I've been trying to implement a siamese neural network in Torch/Lua, as I already explained here. Now I have my first implementation, that I suppose to be good. Unfortunately, I'm facing a problem: during training back-propagation, the gradient descent does not update the error. That is, it always computes the...

Luajit: accessing objects of type cdata from C or C++


c++,c,lua,luajit
All is in the title... Apparently it is not possible to convert cdata to userdata, and I couldn't find any function in the C api to push/retrieve cdata to/from the stack. Maybe there's a simple and recommended way to do it that I haven't noticed? Thanks for your help.

Computercraft Evaluate and Execute relative to ticks


lua,computercraft
For the sake of writing fast turtle programs, I am wondering how, in relation to ticks, is code executed? Is there a tick penalty for executing functions or evaluating other Lua statements in addition to the time it takes the turtle to move? In other words, does it take the...

Write lua_requiref in lua5.1


module,lua,load
I would like to use the function lua_requiref, but in lua5.1. Is there a way to get the effect of lua_requiref in lua 5.1?...

Yaw, pitch, and roll rotations to six float variables


lua,calculus,angles
I need help creating a function to convert three angles (in degrees, yaw pitch and roll) to six float variables. How would I go about making a function output these floats? {0, 0, 0} = {1, 0, 0, -0, -0, 1} {45, 0, 0} = {0.70710676908493, 0.70710676908493, 0, -0, -0,...

Trouble connecting to ESP8266 NodeMCU Server


html,http,lua,arduino,wifi
I have been having trouble connecting to my ESP-01 Wifi module running NodeMCU. I have set up a simple server, but whenever I try to connect to the IP Address via my browser, my browser times out. I know I am making connection to the device because I can see...

horizontal movement in game (rotated player)


math,lua,logic,love2d
In my world I have a character wich is always rotated towards the mouse. It is very logical that when the player moves forward or backward, that the character's x coordinate equals it's x coordinate minus (or plus) the cosine of its x coordinate. And the same for its y...

iterating over a table passed as an argument to a function in lua


for-loop,lua,iterator,lua-table
I am trying using the for _ in pairs() notation to iterate over a table within a function, but if I type anything, even gibberish like print('asdgfafs'), nested inside the for loop, it never gets printed. Code: record = {bid1,bid2,bid3} bid1 = {bidTime = 0.05,bidType = 'native'} bid2 = {bidTime...

2D Line reflection on a “mirror”


math,lua,love2d
So I've been working at this on and off for a week, googling and all and I haven't found how to do this. I have a table of "rays" and a table of "lines", and I want the lines to act as mirrors and reflect a ray whenever the ray...

ROBLOX Lua Error in script: '=' expected near ''


lua,roblox
Hello I am writing a scipt on ROBLOX and I have encountered a problem. function showVictoryMessage(playerName) local message = Instance.new("Message") message.Text = playerName .." has won!" message.Parent = game.Workspace wait (2) message.Destroy() end Upon running this function, or more specifically the "message.Destroy" command, I get the error: Error in script:...

conditional assignment of multiple values


lua,variable-assignment
I've got a function that either can take two parameter, or calls another function to retreive these values(semi-defaults in that case). Let's say the first function looks like this: -- the actuall issue function: function foo( param_1, param_2 ) local bar_1, bar_2 = param_1, param_2 or getBar() -- make funny...

Nginx disable or decode url encoding when writing to access log


nginx,lua,openresty
I have an open resty nginx with lua code that enhance the data and then I write this data to the access log for data analysis. The data that the lua code produce includes double quotes but nginx write it to the access log as \x22. Can I disable this...

Awesome desktop manager widgets


lua,widget,awesome-wm
I came upon this problem before, but only now it really renders awesome desktop manager useless. I was searching how to connect to Wifi with awesome. Found Gigamo Wifi Widget. Cool, how do I eat it? The awesome wiki entry on widgets does not really answer this question. I know...

Lua: how to check whether a process is running


process,lua
I would like to start a process from Lua and monitor whether the process is still running. [EDIT] I know starting can be achieved by os:execute, but this is blocking. I would like to find a way to start a process non-blocking and monitor whether it still runs....

Luarocks can't install a library


lua,luarocks
I want to install this library: https://luarocks.org/modules/dodo/lua-dbus I do luarocks search lua-dbus There are 0 results. sudo luarocks install lua-dbus doesn't install anything as well. The problem is only with this library, because I can search for other libraries on luarocks, for example luarocks search socket gives plenty of matches....

Lua - Is it possible to check if 2 functions are equal?


function,lua,byte,equals
Is it either possible to get the size of a function in bytes to see if it matches another function similar to C++ sizeof operator, or evaluate two functions some other way to see if they are both equal without actually knowing what the function/s are? Example: local function equals(func1,...

Write to file using Lua FFI


file,lua,ffi,luajit
I am trying to use Lua FFI using LuaJIT to append some text to a file, but I am not very knowledgable of C, so I have some trouble. This is the code: local ffi = require "ffi" ffi.cdef[[ typedef int __kernel_ssize_t; typedef __kernel_ssize_t ssize_t; ssize_t write(int fildes, const void...

Lua in pairs with same order as it's written


loops,lua,order,lua-table
Is there any way to loop trough a table like the one below in the same order as it's written? local tbl = { ["hello"] = 1, [2] = 2, [50] = 3, ["bye"] = 4, [200] = 5 } What I mean is that when I use "in pairs"...

How to Draw Circle, incrementally, to create an animated fill effect (using Corona)


lua,geometry,corona,geometry-surface
I'm having trouble even figuring out where to start with this. ANY help would be highly appreciated! Using the Corona SDK I want to draw a circle that will slowly fill as a percentage increases. The fill effect will follow the path of the circle, going anti-clockwise until the entire...

Lua os.tempname


lua,temp
The file names returned by the Lua os.tempname function are weak in two respects Unlike most other languages it is not possible to define a custom prefix for the file name The _6char suffix that is generated can, with brute force but nevertheless, be guessed I have at times used...

Erlang spawning large amounts of C processes


c,multithreading,lua,erlang,ffi
I've been looking into how I could embed languages (let's use Lua as an example) in Erlang. This of course isn't a new idea and there are many libraries out there that can do this. However I was wondering if it was possible to start a Genserver with state which...

MAMP or Mac nginx MySQL Lua


mysql,nginx,lua,osx-server
I've recently purchased a Mac Mini with the only purpose of being a server. I'm a C programmer, learning Lua and Obj-C at the moment. I'm trying to set up a website, a kind of CV/Personal Promotion site. I've been looking at MAMP for a while however, I would like...

Lua import strings from file


string,variables,lua
I can't load my user.db into Lua. user.db contains: user1="XYZ1" user2="Xzy2" .... admin="ZXY" Some Bash and Python scripts use the same db. For Bash e.g. I used the source user.db command, but I don't have a clue for lua. Should be something similiar outside?! I tried the require function but...

Redis Cluster: Find which master holds particular key/slot


lua,redis
I'm using Redis Cluster, and some keys have a special prefix {foo}, so redis puts them in one slot. I do this because i want to run some lua scripts against these keys (i can do this if i login to the master as a single instance). In my setup...

lua - table.concat with string keys


lua,lua-table
I'm having a problem with lua's table.concat, and suspect it is just my ignorance, but cannot find a verbose answer to why I'm getting this behavior. > t1 = {"foo", "bar", "nod"} > t2 = {["foo"]="one", ["bar"]="two", ["nod"]="yes"} > table.concat(t1) foobarnod > table.concat(t2) The table.concat run on t2 provides no...

Multiline function tables in lua


lua
I cannot seem to find any other online help about creating a table which contains functions which are multiline. For example, here is a snippit of code from the lua wiki. action = { [1] = function (x) print(1) end, [2] = function (x) z = 5 end, ["nop"] =...

Reading a table when function has many argument return an error


c++,arrays,lua,arguments,lua-table
I'm trying to read an array inside a Lua function in a library that I'm developing. When I call the function with one argument, like xyz = {3, 4, 5} setxyz(xyz) I read the array correctly, while if I add a second argument xyz = {3, 4, 5} setxyz(xyz, 3)...

Call download lua script in app


c++,lua
I am trying to develop a game by using the c++ with lua, and I am using the quick-cocos2d-x engine to help me finish that. The problem is: I need user to download the lua scripts into their sdcard on their iphone/android devices, so that I can call the function...

Fast way to initialize a tensor in torch7


for-loop,matrix,lua,deep-learning,torch
I need to initialize a 3D tensor with an index-dependent function in torch7, i.e. func = function(i,j,k) --i, j is the index of an element in the tensor return i*j*k --do operations within func which're dependent of i, j end then I initialize a 3D tensor A like this: for...

Lua error loading module 'libpng' (Torch, MacOSX)


osx,lua,osx-yosemite,libpng,torch
How do I make libpng load properly in Lua? I am running Lua/Torch in iTorch Notebook in Mac OSX 10.10.3, where other basic functions in Lua work, such as plotting and calculations. brew install libpng Warning: libpng-1.6.17 already installed If I run: require 'nn'; require 'image'; itorch.image(image.lena()) error loading module...

Sorting 2D boxes into larger boxes to fill in the most efficient and complete manner


sorting,lua,2d,love2d
Background: Hello, so I've been working on this function for a bit and I'm stumbling. Ultimately, what I'm trying to accomplish is to have an application where a user inputs larger boxes, and also inputs a list of smaller boxes. (All 2 dimensional, by the way). The program then processes...

Return multiple values to a function, and access them separately in Lua?


lua
If I have a function that returns multiple values, how can I access those values separately? Something like table[i]. angles = function() x = function() local value = 0 return value end y = function() local value = 90 return value end z = function() local value = 180 return...

Recursive loop stopping after a short time


lua,computercraft
Lua in ComputerCraft 1.5 This seems to work but the recursive loops is breaking after 4 or 5 times running. Cannot seem to see why. Am i doing something incredibly wrong here? Full Code Snippet for the loop: x = 1 function loop() if x > 0 then getTarg() derp1()...

Convolution Neural Network in torch. Error when training the network


lua,neural-network,torch
I am trying to base my Convolution neural network upon the following tutorial: https://github.com/torch/tutorials/tree/master/2_supervised The issue is that my images are of different dimensions than those used in the tutorial. (3x200x200). Also I have only two classes. The following are the changes that I made : Changing the dataset to...

Run Lua script from Python


python,lua,lupa
Suppose I have a Lua script that contains 2 functions. I would like to call each of these functions with some arguments from a Python script. I have seen tutorials on how to embed Lua code in Python and vice versa using Lunatic Python, however, my Lua functions to be...

Lua function selector


function,random,lua,selector
I have 3 functions. When the user presses the 'E' key I want it to select one of the functions (at random), I feel like it has something to do with math.random but I can't figure it out.

Reading Lua Table from C++


c++,lua
I have tried many alternatives for this simple thing but could not get it work. I want user to define a table from Lua in the 1st step: a={["something"]=10} -- key=something, value=10 Then, in the second step the user will call from Lua a function designed in C++: b=afunction(a) --...

How do I do user inputs on the same line in Lua?


input,io,lua
Here is my code: while true do opr = io.read() txt = io.read() if opr == "print" then print(txt) else print("wat") end end What I'm trying to do is make it where you type print and then whatever you want like this: print text And it'll print text but I...

Lua - Function That Creates Detours


class,oop,pointers,lua,clone
I need to make several detours to various functions and doing it one by one is just not an option. I'm looking for a function that will take a table, ideally, and this table is class. Loop through it and for each key, value pair that is a function make...

storyboard.removeScene(“scene name”) is not working


android,gridview,lua,corona
I am new to corona sdk and trying to build sample in it. i want to get back to main screen automatically after some time by destroying my scene(i mean that scene destroys itself after some particular time and user get back to main screen).I know that for some this...

Corona sdk not view random text


text,random,lua,corona
I'm have a problem because when I touch my button sometimes my text doe not appear and I do not understand what is wrong. Code: function randomText(event) display.remove(mmDis) local a = {"Cristiano ronaldo jest najlepszy!", "messi jest dobry!","lewandowski jest ok","diego lopez to bramkarz realu"} com = (a[math.random(1,#a)]) local mmDis =...

Degree value to two float variables


lua,angles
I need help creating a function to convert an angle to two float variables. Here are some examples of the outputs: 0 degrees = {1, 0} ~31.0760 degrees = {~0.92823970, ~0.37198266} 45 degrees= {~0.70707070, ~0.70707070} 90 degrees = {0, 1} 135 degrees = {~-0.707070707, ~0.707070707} 180 degrees = {-1, 0}...

How to iterate through a table in its exact order?


loops,for-loop,lua,order
If i try to output this table, they are looped through in the false order: local letters = {DIN1="hi", AIN1= "my", AIN2 ="name", DIN2="is"} for name, value in pairs(letters) do print(name,value) end Expected Output: DIN1 hi AIN1 my AIN2 name DIN2 is Output: AIN1 my DIN2 is DIN1 hi AIN2...