Lua: Calling functions of another script

Post new mods and scenarios here.

Moderator: MOD_Command

Post Reply
hawkeye_de
Posts: 51
Joined: Sun Apr 19, 2009 5:33 am

Lua: Calling functions of another script

Post by hawkeye_de »

Is it not possible to use require in the Lua sandbox of CMNO ?

So, I have a script file in the Lua directory

function testFunction(unit)
return unit.name
end


and try to call in the console:

myModule = require "myModule"
myModule.testFunction(unit)


as error I get

ERROR: [string "chunk"]:2: attempt to call global 'require' (a nil value)

If require does not work, is there any other means to create reuse functions, which I could reuse ?

Thanks.
DeSade
Posts: 155
Joined: Mon Mar 01, 2004 5:08 pm
Contact:

RE: Lua: Calling functions of another script

Post by DeSade »

try ScenEdit_RunScript (script):

http://commandlua.github.io/#ScenEdit_RunScript

script (library usually) should reside in Lua folder
Dimitris
Posts: 14792
Joined: Sun Jul 31, 2005 10:29 am
Contact:

RE: Lua: Calling functions of another script

Post by Dimitris »

One of the things coming in v1.07 is that you'll be able to bundle such scripts with the scen you are distributing and have it work "out of the box" without having to instruct the end player to do anything ("place this file here" etc.).
hawkeye_de
Posts: 51
Joined: Sun Apr 19, 2009 5:33 am

RE: Lua: Calling functions of another script

Post by hawkeye_de »

Hm...the Runscript is not the same as require

For instance, it does not allow you to bind external libraries. Also, my understanding is that RunScript executes a script but not a function.

Additionally:
ZeroBraneStudio IDE (http://studio.zerobrane.com/doc-remote-debugging) supports remote debugging...that is you should be able to debug embedded scripts. See for a usecase here: http://notebook.kulchenko.com/zerobrane ... ane-studio

But to do so, you need to bind a library...
Dimitris
Posts: 14792
Joined: Sun Jul 31, 2005 10:29 am
Contact:

RE: Lua: Calling functions of another script

Post by Dimitris »

Hawkeye, how's your SSN sim going? I recently tried accessing your blog on it but seems to have vanished.
hawkeye_de
Posts: 51
Joined: Sun Apr 19, 2009 5:33 am

RE: Lua: Calling functions of another script

Post by hawkeye_de »

ORIGINAL: Sunburn

Hawkeye, how's your SSN sim going? I recently tried accessing your blog on it but seems to have vanished.

I've disabled the blog....the feedback which I've got was quite limited, so I've thought it is not worth the effort.

Frankly, I've developed it not so much further in the last 2-3 months. To do this alone in your spare time is really tough. I think developing such a sim like you in a team, would make much more sense.

Also from a game design perspective, there is the issue (in contrast to Command) that submarine combat is really slow. So, atmosphere is important, which translates into the fact, that you need a sophisticated UI experience. A hell of work ;)

Anyways, here are some screenshots from the current build:

http://www.directupload.net/file/d/3858 ... u3_jpg.htm
http://www.directupload.net/file/d/3858 ... ua_jpg.htm
http://www.directupload.net/file/d/3858 ... 3d_jpg.htm
http://www.directupload.net/file/d/3858 ... 7y_jpg.htm
Post Reply

Return to “Mods and Scenarios”