ULX

Author Topic: Screwy Usage of External Functions  (Read 184 times)

0 Members and 1 Guest are viewing this topic.

Offline BlueNova

  • Full Member
  • ***
  • Posts: 108
  • Karma: 11
  • The most powerful force in the universe.
Screwy Usage of External Functions
« on: January 26, 2019, 10:00:39 AM »
Hi all

I've got this weird problem and I thought that some extra opinions would help me with it, so I have an external function called getIndex that just simply returns the index of an item in a table. Weird part is is that it's called in another file of mine and works just fine but when I call it for this other purpose I get the following error

Code: [Select]
[ERROR] addons/hydra_ttt/lua/hydra_ttt/framework/sh_groups.lua:23: attempt to call global 'getIndex' (a nil value)
Here's the code of the function

Code: Lua
  1. function getIndex(tbl, value)
  2.     for k, v in pairs(tbl) do
  3.         tbl[v] = k
  4.     end
  5.  
  6.     return tbl[value]
  7. end

Here's a working example of it's use in a file I call sh_playerstuff.lua

Code: Lua
  1. table.insert(args, getIndex(args, v), funny_words[math.random(1, #funny_words)])

And then here's an example where I get the error above in a file called sh_groups.lua
Code: Lua
  1. local group_name = string.Split(self:GetUserGroup(), "") --Just incase you're wondering what some of the variables below were for/from
  2. table.insert(group_name, getIndex(group_name, "m"), string.upper(v))

I've tried using AddCSLuaFile but oddly enough in first file, where it works, doesn't require it.

Any help/input would be appreciated, thanks.
If you need anymore info just let me know
« Last Edit: January 26, 2019, 10:02:48 AM by BlueNova »

Offline BlueNova

  • Full Member
  • ***
  • Posts: 108
  • Karma: 11
  • The most powerful force in the universe.
Re: Screwy Usage of External Functions
« Reply #1 on: January 26, 2019, 02:49:41 PM »
Update on this

So I managed to get everything working with just using AddCSLuaFile() on the top of the files where I needed the function specifically, but it still confuses me why sometimes I'll need AddCSLuaFile and sometimes I won't, just seems kind of odd to me

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 7972
  • Karma: 373
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Screwy Usage of External Functions
« Reply #2 on: January 26, 2019, 07:29:22 PM »
3-second guess answer - "self" is a 100% local meta, and local to (client).
Perhaps any other time it's called ( and works ) is server side.

The price one pays for pursuing any profession or calling is an intimate knowledge of its ugly side. - James Baldwin

Offline BlueNova

  • Full Member
  • ***
  • Posts: 108
  • Karma: 11
  • The most powerful force in the universe.
Re: Screwy Usage of External Functions
« Reply #3 on: January 26, 2019, 07:51:06 PM »
3-second guess answer - "self" is a 100% local meta, and local to (client).
Perhaps any other time it's called ( and works ) is server side.



You guessed correctly, didn't think of that