Equivalent to LUAUI_DIRNAME for LuaRules directory?
Moderator: Moderators
Equivalent to LUAUI_DIRNAME for LuaRules directory?
Is there something similar to "LUAUI_DIRNAME" but for LuaRules?
Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?
Maybe there's none because dir name would be different accross users and LuaRules has to remain synced?
Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?
LuaRules is always in LuaRules. LuaUI can move: example is versioned LuaUI folders, but I don't think the use of it is common.
Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?
Oh thanks for the information :)
The thing is I try to take a widget and make it a gadget. I renamed all "widget" keywords to "gadget" but then noticed that I get errors when loading some special fonts.
Here is the widget code:
I tryied renaming taking away the LUAUI_DIRNAME and replacing it with "../" and "/../" but none of those work although that i also moved the apropriate folders needed. From the first line removing LUAUI_DIRNAME gives an error about a string argument found or sth. 
The structure is as follows:
LuaRules/Gadgets/gadgetthatruns.lua
LuaRules/Fonts/*
LuaRules/Images/*
LuaRules/modfonts.lua
The thing is I try to take a widget and make it a gadget. I renamed all "widget" keywords to "gadget" but then noticed that I get errors when loading some special fonts.
Here is the widget code:
Code: Select all
local fontHandler = loadstring(VFS.LoadFile(LUAUI_DIRNAME.."modfonts.lua", VFS.ZIP_FIRST))()
local panelFont = LUAUI_DIRNAME.."Fonts/FreeSansBold_14"
local waveFont = LUAUI_DIRNAME.."Fonts/Skrawl_40"
local panelTexture = ":n:"..LUAUI_DIRNAME.."Images/panel.tga"
The structure is as follows:
LuaRules/Gadgets/gadgetthatruns.lua
LuaRules/Fonts/*
LuaRules/Images/*
LuaRules/modfonts.lua
Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?
Gadgets usually go:
if (gadgetHandler:IsSyncedCode()) then
-- SYNCED STUFF
else
-- UNSYNCED STUFF
end
Graphical stuff like fonts and texture go into UNSYNCED. Then I'm not sure saying that will really solve your problem. But on the long run it'll probably help to know about that specificity of gadgets that isn't present in widgets.
if (gadgetHandler:IsSyncedCode()) then
-- SYNCED STUFF
else
-- UNSYNCED STUFF
end
Graphical stuff like fonts and texture go into UNSYNCED. Then I'm not sure saying that will really solve your problem. But on the long run it'll probably help to know about that specificity of gadgets that isn't present in widgets.
- CarRepairer
- Cursed Zero-K Developer
- Posts: 3359
- Joined: 07 Nov 2007, 21:48
Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?
Leave all the fonts in your LuaUI folder and add this line to your gadget:
Code: Select all
LUAUI_DIRNAME = 'LuaUI/'Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?
Yes, that actually solved the problem though now I ran into an other:
(from line 25 to 28)
Any idea about that? I tryied running the code with "if..IsSyncedCode", "if (not..IsSyncedCode" and even running the same code in both cases with resulted in nothing different :/
Though on line 25 I have nothing that has to do with a global or a string:Failed to load: gui_bot.lua ([string "-- $Id$..."]:25: attempt to index global 'gl' (a nil value))
(from line 25 to 28)
Code: Select all
if (not Spring.GetGameRulesParam("difficulty")) then
--return false
Spring.Echo("RETURN!!!!!(line 27)")
endRe: Equivalent to LUAUI_DIRNAME for LuaRules directory?
It sounds like the problem is not on line 25, but on some other line, one that uses gl.something
Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?
well the thing is that when it was a widget it worked as it was. is it possible that gadgets can't use the same global variables that widgets do?
Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?
You can't do gl operations on the synced side of Gadgets, nor within certain Gadget operations. Pastebin would be handy, if we're to help.
Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?
Well pastebin had some php issue so i used codepad: http://codepad.org/Qfz06kmh
The reason I didn't post the code earlier is that it's 400 lines and maybe a bit messy to read. Keep in mind that most code that I added is included into comments of the form "-- Bot Defense Code Here***..". The rest is mostly gui_chicken.lua code though with less code than the original
The reason I didn't post the code earlier is that it's 400 lines and maybe a bit messy to read. Keep in mind that most code that I added is included into comments of the form "-- Bot Defense Code Here***..". The rest is mostly gui_chicken.lua code though with less code than the original
Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?
Well, stuff like your fonthandling, the CreatePanelDisplayList function, DrawScreen, MousePress, etc... should be in the unsynced side of the gadget. Stuff like UnitDestroyed or spawning waves of chickens should be in the synced side.
Right now you don't have any "if gadgetHandler:IsSyncedCode() then" so all the code is in both side, synced and unsynced. And of course gl.PushMatrix(), being a graphic command, isn't defined on the synced side, hence your error.
I mean, since you're copying BA chicken defense, look for instance at BA's s unit_spawner_defense.lua. Right after the gadget:GetInfo(), you see a if (gadgetHandler:IsSyncedCode()) then, and then in the middle of the gadget... ok at the end of the gadget there's an else, which marks a clear delimitation between the simulation-changing logic and the GUI display ... which is delegated to a widget so not a good exemple. Meh, I don't know, look for exemple at KP's shoot'n'run gadget to see what I mean with synced/unsynced sides of gadget.
Right now you don't have any "if gadgetHandler:IsSyncedCode() then" so all the code is in both side, synced and unsynced. And of course gl.PushMatrix(), being a graphic command, isn't defined on the synced side, hence your error.
I mean, since you're copying BA chicken defense, look for instance at BA's s unit_spawner_defense.lua. Right after the gadget:GetInfo(), you see a if (gadgetHandler:IsSyncedCode()) then, and then in the middle of the gadget... ok at the end of the gadget there's an else, which marks a clear delimitation between the simulation-changing logic and the GUI display ... which is delegated to a widget so not a good exemple. Meh, I don't know, look for exemple at KP's shoot'n'run gadget to see what I mean with synced/unsynced sides of gadget.
Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?
Well, basically you forgot to specify synced/unsynced operation space. Here's a basic fix:
http://pastebin.com/uM41yMku
For more than that, you'll need to test it, I haven't had time. I think that may resolve your primary issue, though.
http://pastebin.com/uM41yMku
For more than that, you'll need to test it, I haven't had time. I think that may resolve your primary issue, though.
Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?
Thanks a lot for the help. I kind of managed to fix the counting. The only problem is that I am not available to see the panel. The counting works though as I tested with "Spring.Echo".
The problem is that the panel never appears and no errors are shown.
http://pastebin.com/HSv3vWBP
By the way now I have put some variables that I want to be used by both synced and unsycned block of code. Should I have those variables outside the "ifSynced else " or do those share the same scope? So if I have a variable "x" in the synced block, is it going to be possible to read that variable in the unsynced block?
And lastly how many initialize should I have? one for synced and one for unsynced or a main one outside the synced/unsynced?
The problem is that the panel never appears and no errors are shown.
http://pastebin.com/HSv3vWBP
By the way now I have put some variables that I want to be used by both synced and unsycned block of code. Should I have those variables outside the "ifSynced else " or do those share the same scope? So if I have a variable "x" in the synced block, is it going to be possible to read that variable in the unsynced block?
And lastly how many initialize should I have? one for synced and one for unsynced or a main one outside the synced/unsynced?
Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?
I tested a bit more and it seems that "function gadget:GameFrame(n)" inside "unsynced" is never triggered. So I guess I have to use it in the synced code. But how do I do that as it's going to update the panel which is an unsynced thingy? :S
Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?
You could use the :Update callin, which is called rapidly while spring runs (and is also called while game is paused, which GameFrame isn't)Pithikos wrote:I tested a bit more and it seems that "function gadget:GameFrame(n)" inside "unsynced" is never triggered. So I guess I have to use it in the synced code. But how do I do that as it's going to update the panel which is an unsynced thingy? :S
Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?
But how am I supposed to use that?
I wrote this in the unsynced part:
And was expecting that the function UpdateRules would update all the time and get an echo "Update CallIn" but nothing happens.
I wrote this in the unsynced part:
Code: Select all
function gadget:UpdateCallIn(UpdateRules)
echo("Update CallIn")
end
Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?
Pithikos wrote:But how am I supposed to use that?
I wrote this in the unsynced part:
And was expecting that the function UpdateRules would update all the time and get an echo "Update CallIn" but nothing happens.Code: Select all
function gadget:UpdateCallIn(UpdateRules) echo("Update CallIn") end
Code: Select all
function gadget:Update()
Spring.Echo("Update")
endRe: Equivalent to LUAUI_DIRNAME for LuaRules directory?
Ok thanks it kind of works. But isn't that a bit CPU consuming?
