ULX

Author Topic: calling functions outside of the modules folder  (Read 1400 times)

0 Members and 1 Guest are viewing this topic.

Offline fartrage

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
calling functions outside of the modules folder
« on: December 15, 2015, 12:25:00 AM »
Hi there, so i've been working on a small addon for gmod to make an effective buildmode script.
All has been going fine so far, and i wanted to add support for ulx loggs.

I've ran into a problem where i can't seem to get
Code: [Select]
ulx.logWriteln("Player:"..ply:Nick().."changed build mode") to work, outside or inside of the modules folder.

For example. i have defined 
Code: [Select]
function LogBuildMode(ply,bool) inside of my "\addons\BuildMode\lua\ulx\modules\sh"

and it is being called in "\addons\BuildMode\BuildMode" with 
Code: [Select]
LogBuildMode(ply,bool)
the build mode addon itself is loaded with an include file at "\addons\BuildMode\lua\autorun"


To my knowlege, lua defined functions should be able to be called from different scripts as long as they are not marked as local functions. Is this correct?

if i haven't messed up somewhere, the only thing i can think of is that it would be some kind of load order problem, in which the addon itself is read, but it can't find the function because ulx has not loaded.

I've also tried removing the need to comunicate functions across different scripts by simply adding
Code: [Select]
ulx.logWriteln("Player:"..ply:Nick().."changed build mode") inside the addon itself  outside of the "modules/sh" folder, but that didn't seem to work either.


Is this some kind of scope problem, or some kind of load order problem?

Thanks for any help. :)

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: calling functions outside of the modules folder
« Reply #1 on: December 15, 2015, 09:36:37 AM »
It's very likely a load order problem. You should put server-side scripts that rely on ULX (or at least the sections of code you need) in the <your addon>\lua\ulx\modules\ folder, then use the cl\ or sh\ folder for client-side or shared scripts respectively.
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6