Lua Module for ScriptedRotation

All about writing scripts for Celestia in Lua and the .cel system
Topic author
Pierral
Posts: 10
Joined: 16.01.2008
With us: 16 years 10 months
Location: Cannes, FR

Lua Module for ScriptedRotation

Post #1by Pierral » 12.02.2008, 14:07

Hello !

I'm trying to make a Lua module for an object which has a ScriptedRotation. But for some reason I don't understand, Celestia tells me "Failed to load module for ScriptedRotation" every time I start.
I have my module "rtfifo.lua" in "scripts/celxx" directory, and here is my module :

Code: Select all

rtAttProto = { }

-- constructor method

function rtAttProto:new(o)
   o = o or {}
   setmetatable (o, self)
   self.__index = self

   o.period = 1

   return o
end

-- orientation function

function rtAttProto:orientation(tjd)
   local t = tjd

   -- return a quaternion representing the orientation
   w, x, y, z = fifolib.popAtt(t)

   return w, x, y, z

end

function rtAtt(sscvals)

   return rtAttProto:new(sscvals)

end


And here is the .scc

Code: Select all

    ScriptedRotation
    {
        Module "rtfifo"
        Function "rtAtt"
    }


"fifolib" is a library I made and added to Lua. It works very well in a celx script launched with celestia, and i was asking why it does not in Lua module. But after some research, I found that the module was not even loaded.
Can someone help me with Lua Module and Scc file please ?
I already read wiki documentation, i downloaded and analyzed "flight_control" script, and i think i did the same, but it does not work for me... :cry:

Thanks !

Pierral.

Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 2 months
Location: NY, USA

Post #2by selden » 12.02.2008, 14:22

CELX scripts, LuaHooks, and Scripted SSC functions run in three separate contexts. Routines and libraries loaded in one context are not available to the others. Your Scripted module needs to explicitly load the libraries that it needs.

Some, but not all, Lua syntax errors are reported in Celestia's console log. Type a tilde (~) to see it, and use the arrow keys to navigate up and down in it. If your keyboard supports diacritical marks, you may have to type <tilde><space>
Selden

Topic author
Pierral
Posts: 10
Joined: 16.01.2008
With us: 16 years 10 months
Location: Cannes, FR

Post #3by Pierral » 12.02.2008, 14:28

Ok thanks Selden. I'll explicitly declare my "fifolib" with require in my "rtfifo.lua" file.

But do you think it's because of that i have the error "Failed to load module rtfifo" (in scriptrotation.cpp::initialize) ?

Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 2 months
Location: NY, USA

Post #4by selden » 12.02.2008, 14:37

"failed to load module" is caused by any error in the module. You need to look at the line of the console log where it says the SSC file was loaded. Many (but not all) module errors generate an error message which includes the module line number where Lua detected an error. That might not be the actual cause of the problem, though. Incorrectly nested end statements will generate misleading line numbers, for example.
Selden

Topic author
Pierral
Posts: 10
Joined: 16.01.2008
With us: 16 years 10 months
Location: Cannes, FR

Post #5by Pierral » 12.02.2008, 14:44

Ok so it's a Lua error, thanks !

Can i abuse and ask you where can i find the console log please ?

Thanks for all !

Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 2 months
Location: NY, USA

Post #6by selden » 12.02.2008, 14:50

Type a tilde (~) to see Celestia's console log, and use the arrow keys to navigate up and down in it. If your keyboard supports diacritical marks, you may have to type <tilde><space>
Selden

Topic author
Pierral
Posts: 10
Joined: 16.01.2008
With us: 16 years 10 months
Location: Cannes, FR

Post #7by Pierral » 12.02.2008, 15:12

Yes !!!!
Thanks Selden ! that's a tricky command, but it's so helpfull !!!
I found that i was not in the good directory, and now i can see lua error and lines !
I can debug my script now !!
thanks a lot !! :D

Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 2 months
Location: NY, USA

Post #8by selden » 12.02.2008, 15:15

You are very welcome.
Selden


Return to “Scripting”