GoldenEye: Source Forums

  • November 22, 2024, 12:26:55 am
  • Welcome, Guest
Advanced search  

News:

Pages: 1 [2] 3   Go Down

Author Topic: Read Me  (Read 19191 times)

0 Members and 1 Guest are viewing this topic.

Slinky

  • Agent
  • *
  • Posts: 8
  • Reputation Power: 0
  • Slinky has no influence.
  • Offline Offline
Re: Read Me
« Reply #15 on: July 19, 2009, 04:28:02 am »

Hi, what's the working directory for running lua scripts?  I'm trying to put some reusable logic into a separate script so I can use it for later game types.  Unfortunately, no matter where I put the included file, when I try to use, "dofile(gamecycle.lua)" to include it, I get a message in the console saying that there is no such file or directory as gamecycle.lua.  Is there any solution for this?
Logged

Mark [lodle]

  • Retired Lead Developer
  • 007
  • *
  • Posts: 1,411
  • Reputation Power: 1
  • Mark [lodle] has no influence.
  • Offline Offline
Re: Read Me
« Reply #16 on: July 19, 2009, 07:42:18 am »

i dont think we support that as i have never had to use it. If you show me your script i can debug it and make it work. :P
Logged

Slinky

  • Agent
  • *
  • Posts: 8
  • Reputation Power: 0
  • Slinky has no influence.
  • Offline Offline
Re: Read Me
« Reply #17 on: July 19, 2009, 05:14:56 pm »

The script was pretty simple because I was just trying to get this working before stepping into the whole thing:

In eliminatio.lua:
Code: [Select]
dofile("gamecycle.lua");

function Think()
   TestFunc();
end

In gamecycle.lua:
Code: [Select]
function TestFunc();
   ClientPrintAll(HUD_PRINTCENTER, "TEST");
end
Logged

Mark [lodle]

  • Retired Lead Developer
  • 007
  • *
  • Posts: 1,411
  • Reputation Power: 1
  • Mark [lodle] has no influence.
  • Offline Offline
Re: Read Me
« Reply #18 on: July 19, 2009, 06:47:09 pm »

Ill give it ago tomorrow.
Logged

killermonkey

  • GES Programmer
  • Retired Lead Developer
  • GE:S Fanatic
  • *
  • Posts: 5,473
  • Reputation Power: 346
  • killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!
  • Offline Offline
    • DroidMonkey Apps
Re: Read Me
« Reply #19 on: July 19, 2009, 11:40:50 pm »

Try using loadfile(filename)

Make sure the file is in the same directory as the current LUA script. If this doesn't work, try putting the lua file that you want to load in:

....\steam\steamapps\_STEAMNAME_\Source SDK Base 2007\  just for shits and giggles and see if it loads...

Then try putting it in the base directory of the mod (gesource) and try it again. The thing I am trying to get you to test is to see where the entry point of loading files is located. Since we bind LUA to source there are MANY entry points, I am not sure that we define any specific directory as a load point and there is no documentation on dofile or loadfile that describes how LUA handles the entry point...
« Last Edit: July 19, 2009, 11:43:21 pm by killermonkey »
Logged

Slinky

  • Agent
  • *
  • Posts: 8
  • Reputation Power: 0
  • Slinky has no influence.
  • Offline Offline
Re: Read Me
« Reply #20 on: July 20, 2009, 05:05:22 am »

With gamecycle.lua and elminatio.lua int he same directory, and using dofile(), I get that error.  However, when I change it to loadfile(), I no longer get a "no such file or directory" error.  However:

Previously when Think() ran, it said that it had a problem trying to call a nil value, with no additional details.
Now it throws an error when calling think():  'attempt to call global TestFunc: a nil value'.  So that says to me that loadfile() may still be failing, but silently.  This happens when gamecycle.lua is in the other two directories you named as well.

Logged

Slinky

  • Agent
  • *
  • Posts: 8
  • Reputation Power: 0
  • Slinky has no influence.
  • Offline Offline
Re: Read Me
« Reply #21 on: July 20, 2009, 05:11:23 am »

I've just verified- I removed gamecycle.lua from my steam folders completely and it's still doing the same thing, so probably not reading gamecycle.lua successfully.
Logged

Slinky

  • Agent
  • *
  • Posts: 8
  • Reputation Power: 0
  • Slinky has no influence.
  • Offline Offline
Re: Read Me
« Reply #22 on: August 01, 2009, 08:19:09 pm »

Was there ever an answer discovered for this?
Logged

killermonkey

  • GES Programmer
  • Retired Lead Developer
  • GE:S Fanatic
  • *
  • Posts: 5,473
  • Reputation Power: 346
  • killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!
  • Offline Offline
    • DroidMonkey Apps
Re: Read Me
« Reply #23 on: August 02, 2009, 01:19:51 pm »

Awesome, here's a reference i just found:

http://www.lua.org/pil/8.1.html

It uses the LUA command require <filename>, where require actually lets you specify a path to search on.

You can set that path by setting the global variable: LUA_PATH to a string and thats it.

I have added direct support for this newly found feature in Beta 4 where the LUA_PATH global variable will be defined based on the full path to gesource/scripts/gameplay  so future use of "require" will be meaningful without declaring your own variable
« Last Edit: August 02, 2009, 02:12:00 pm by killermonkey »
Logged

Slinky

  • Agent
  • *
  • Posts: 8
  • Reputation Power: 0
  • Slinky has no influence.
  • Offline Offline
Re: Read Me
« Reply #24 on: August 02, 2009, 05:46:44 pm »

Awesome, thank you.
Logged

Slinky

  • Agent
  • *
  • Posts: 8
  • Reputation Power: 0
  • Slinky has no influence.
  • Offline Offline
Re: Read Me
« Reply #25 on: August 03, 2009, 02:42:23 am »

Just a note- you may have to add support for the 'require' method itself.  I tried to implement this immediately, figuring that it just wouldn't be able to find my file but instead got this:


Executing listen server config file
[LUA-ERR] Error running function "eliminatio": [string "eliminatio"]:1: attempt to call global 'require' (a nil value)

So it looks like require isn't implemented in 3.1's lua libraries.
Logged

killermonkey

  • GES Programmer
  • Retired Lead Developer
  • GE:S Fanatic
  • *
  • Posts: 5,473
  • Reputation Power: 346
  • killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!
  • Offline Offline
    • DroidMonkey Apps
Re: Read Me
« Reply #26 on: August 03, 2009, 02:44:20 pm »

Shit, looks like you'll have to wait for BETA 4 in order to implement your module system properly. I had to add the "Package Library" to the LUA environment in order to get the 'require' function.

By the way, the proper way to set the path for "require" and not have an environment variable for it is to set:

package.path = "C:/Program Files/Steam/steamapps/SourceMods/gesource_svn/scripts/gameplay/?.lua";

Where package is the global table that comes from the "Package Library."

So this is working wonderfully in Beta 4 now. Sorry that it won't work out for B3.1.4.

Code: [Select]
(C++)
// Define our path
char fullpath[ 512 ] = { 0 };
filesystem->RelativePathToFullPath( "scripts/gameplay", "MOD", fullpath, sizeof(fullpath) );
Q_strncat( fullpath, "\\?.lua", sizeof(fullpath) );

lua_getglobal(GetLua(), "package");
if (LUA_TTABLE != lua_type(GetLua(), 1))
return;
lua_pushlstring(GetLua(), fullpath, Q_strlen(fullpath) );
lua_setfield(GetLua(), 1, "path"); /* package.path = fullpath */


(LUA)
testfunc.lua

function TestFunc()
    ClientPrintAll(HUD_PRINTTALK, "TEST FUNC!");
end


deathmatch.lua

require( "testfunc" );
function PlayerKilled( victim, killer )
TestFunc();
end
Logged

Slinky

  • Agent
  • *
  • Posts: 8
  • Reputation Power: 0
  • Slinky has no influence.
  • Offline Offline
Re: Read Me
« Reply #27 on: August 04, 2009, 03:44:32 am »

Cool, good to  hear this will be fixed in 4.  Thanks so much!
Logged

Mark [lodle]

  • Retired Lead Developer
  • 007
  • *
  • Posts: 1,411
  • Reputation Power: 1
  • Mark [lodle] has no influence.
  • Offline Offline
Re: Read Me
« Reply #28 on: August 04, 2009, 05:30:07 am »

Monkey why dont you checkout 3.1.4 and add this in, send the server dll to slinky so slinky can make sure it works 100% before beta 4. :P
Logged

killermonkey

  • GES Programmer
  • Retired Lead Developer
  • GE:S Fanatic
  • *
  • Posts: 5,473
  • Reputation Power: 346
  • killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!killermonkey is awe-inspiring!
  • Offline Offline
    • DroidMonkey Apps
Re: Read Me
« Reply #29 on: August 04, 2009, 12:44:10 pm »

For someone who doesn't have a lot of time you sure know how to make other people do a lot of work, Mark. :-P

Yah, I'll do that for the poor sap, I'll post it up here for anyone who wants to try, **THIS WILL BE BETA 3.1.4.1 NOT BETA 4 IN ANY WAY**

EDIT:
Beta 3.1.4.1 (added LUA support for the "require" module)
http://www.divshare.com/download/8081271-067
« Last Edit: August 04, 2009, 01:25:32 pm by killermonkey »
Logged
Pages: 1 [2] 3   Go Up