eleXity Posted June 18, 2010 Share Posted June 18, 2010 Hi, I want to make some item scripts in XML like this <class name="item"> <item> <!-- Function block--> <function name="OnPick"> local itemClass = {} itemClass.light = CreateSpotLight() itemClass.light:Hide() </function> <function name="OnUseSwitch"> if (bItem_Used=true) then itemClass.light:Show() else itemClass.light:Hide() end </function> <function name="OnUpdate"> itemClass.light:SetMatrix(this.tItem_PositionPivot.mat) </function> </item> </class> I load every function block into an ScriptFunction type in blitz max and they all have one new instance of a TLuaState so that I can run it with DoString(), but with the new tLuaState the lugi functions are not registered, how should i do that ? hope you understand my problem PS.: sorry for my bad English B) Quote Windows 10 | Intel i5 - 3570K | Nvidia GTX 960 | 16GiB RAM | LE 3 | BlitzMax | C# | Java | German Link to comment Share on other sites More sharing options...
Canardia Posted June 18, 2010 Share Posted June 18, 2010 I think you need to execute your own Lua scripts via a thingoid (which is a model with a lua script). Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
eleXity Posted June 18, 2010 Author Share Posted June 18, 2010 mhh but this is not what i expect, I not want to do something with the entity-lua scripts, I only want that for the entity´s and nothing more B) the item scripts should be separate... I have another question, is it possible to create a lua class from blitzmax and/or invoke functions from within blitzmax like this : function classname:Bla() ? Quote Windows 10 | Intel i5 - 3570K | Nvidia GTX 960 | 16GiB RAM | LE 3 | BlitzMax | C# | Java | German Link to comment Share on other sites More sharing options...
Canardia Posted June 18, 2010 Share Posted June 18, 2010 I think the answer stays the same, you can do any Lua commands and class definitons by loading a model in LE. As long there is no function like RunScript() in LE, there's no other way, unless BlitzMax has some undocumented hack again, which doesn't work with the DLL version. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
eleXity Posted June 18, 2010 Author Share Posted June 18, 2010 the function RunScript(sFile:string) exists in BlitzMax, but you only can run files.. no string´s Quote Windows 10 | Intel i5 - 3570K | Nvidia GTX 960 | 16GiB RAM | LE 3 | BlitzMax | C# | Java | German Link to comment Share on other sites More sharing options...
AndyGFX Posted June 18, 2010 Share Posted June 18, 2010 Q#1: Why you don't write string to a file and then call with RunScript? Q#2: Why you have inserted XML between Lua script and BMX? Why you don't write your class Item like lua class? TItemClass = {} function TItemClass:New() o = { bItem_Used = false } setmetatable(o, self) self.__index = self return o end function TItemClass:OnPick() self.light = CreateSpotLight() self.light:Hide() end function TItemClass:OnUseSwitch() if (self.bItem_Used==true) then self.light:Show() else self.light:Hide() end end function TItemClass:OnUpdate() -- ... end Quote [HW] C2D Q6600, 4GB RAM, NV8800GTX, Vista Ultimate x64 [sW] Blide Plus, BlitzMax, Delphi, C++, 3DWS 5.53, Leadwerks 2.xx Link to comment Share on other sites More sharing options...
AndyGFX Posted June 18, 2010 Share Posted June 18, 2010 mhh but this is not what i expect, I not want to do something with the entity-lua scripts, I only want that for the entity´s and nothing more the item scripts should be separate... I have another question, is it possible to create a lua class from blitzmax and/or invoke functions from within blitzmax like this : function classname:Bla() ? When you want call existing function in lua script you need add to BMX code this part: C sample: http://www.lua.org/manual/2.1/subsection3_7_6.html DELPHI sample: // call LUA function function ExecuteFunction(functionname: pchar): pchar; begin if (enabled = false) then exit; lua_getglobal(VM, functionname); lua_call(VM, 0, 1); result := lua_tostring(VM, 1); //result:=0; end; // call LUA function with int arg function ExecuteFunction(functionname: pchar;val:integer): pchar; var state:integer; begin lua_getglobal(VM, functionname); state := lua_type(VM,-1); lua_pushnumber(VM, val); if (state=LUA_TFUNCTION) then lua_call(VM, 1, 0); end; And at end, my TIP: - add PUB.LUA to your BMX source - then you have this very useful functions added: Function lua_dobuffer:Int (lua_state:Byte Ptr, buff:String, sz:Int, name:String) Function lua_dofile:Int (lua_state:Byte Ptr, filename:String) Function lua_dostring:Int (lua_state:Byte Ptr, str:String) and many others. Quote [HW] C2D Q6600, 4GB RAM, NV8800GTX, Vista Ultimate x64 [sW] Blide Plus, BlitzMax, Delphi, C++, 3DWS 5.53, Leadwerks 2.xx Link to comment Share on other sites More sharing options...
eleXity Posted June 19, 2010 Author Share Posted June 19, 2010 ok thanks for your tips I will try the lua version of it, but i don´t understand how it works.. lets say I run your lua script with RunScript(), how can I then call the function TItemClass:New() from blitzmax to create the new class, or the OnUpdate() function ? or must I only call it like this : lua_getglobal(VM, "TItemClass:New"); lua_call(VM, 0, 1); Ps.: sorry for the noob questions but I never worked with lua before LE Quote Windows 10 | Intel i5 - 3570K | Nvidia GTX 960 | 16GiB RAM | LE 3 | BlitzMax | C# | Java | German Link to comment Share on other sites More sharing options...
AndyGFX Posted June 19, 2010 Share Posted June 19, 2010 I think that for you is now best way, learn LUA with LE Scene editor. You need know, how lua works, then how it works in LE Scene and after this goals to learning, you are partly ready to use lua in BMX or other language. Quote [HW] C2D Q6600, 4GB RAM, NV8800GTX, Vista Ultimate x64 [sW] Blide Plus, BlitzMax, Delphi, C++, 3DWS 5.53, Leadwerks 2.xx Link to comment Share on other sites More sharing options...
eleXity Posted June 19, 2010 Author Share Posted June 19, 2010 do you have some useful links for learning lua ... ? would be nice ^^ Quote Windows 10 | Intel i5 - 3570K | Nvidia GTX 960 | 16GiB RAM | LE 3 | BlitzMax | C# | Java | German Link to comment Share on other sites More sharing options...
AndyGFX Posted June 19, 2010 Share Posted June 19, 2010 http://lua-users.org/wiki/LuaLinks and of course http://www.lua.org/manual/5.1/ Quote [HW] C2D Q6600, 4GB RAM, NV8800GTX, Vista Ultimate x64 [sW] Blide Plus, BlitzMax, Delphi, C++, 3DWS 5.53, Leadwerks 2.xx Link to comment Share on other sites More sharing options...
eleXity Posted June 19, 2010 Author Share Posted June 19, 2010 thank you for your help Quote Windows 10 | Intel i5 - 3570K | Nvidia GTX 960 | 16GiB RAM | LE 3 | BlitzMax | C# | Java | German Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.