Page 1 of 2

Equivalent to LUAUI_DIRNAME for LuaRules directory?

Posted: 01 Nov 2010, 20:41
by Pithikos
Is there something similar to "LUAUI_DIRNAME" but for LuaRules?

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Posted: 02 Nov 2010, 03:45
by zwzsg
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?

Posted: 02 Nov 2010, 06:36
by lurker
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?

Posted: 02 Nov 2010, 07:13
by Pithikos
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:

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"
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

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Posted: 02 Nov 2010, 11:43
by zwzsg
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.

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Posted: 02 Nov 2010, 16:10
by CarRepairer
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?

Posted: 02 Nov 2010, 17:30
by Pithikos
Yes, that actually solved the problem though now I ran into an other:
Failed to load: gui_bot.lua ([string "-- $Id$..."]:25: attempt to index global 'gl' (a nil value))
Though on line 25 I have nothing that has to do with a global or a string:
(from line 25 to 28)

Code: Select all

if (not Spring.GetGameRulesParam("difficulty")) then
  --return false
  Spring.Echo("RETURN!!!!!(line 27)")
end
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 :/

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Posted: 02 Nov 2010, 17:42
by zwzsg
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?

Posted: 02 Nov 2010, 18:21
by Pithikos
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?

Posted: 02 Nov 2010, 21:13
by zwzsg
Yes.

gl. is for graphism, which can't be done in the synced of a gadget. Pastebin the whole gadget?

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Posted: 03 Nov 2010, 06:11
by Argh
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?

Posted: 03 Nov 2010, 08:25
by Pithikos
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

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Posted: 03 Nov 2010, 10:25
by zwzsg
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.

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Posted: 04 Nov 2010, 20:26
by Argh
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.

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Posted: 06 Nov 2010, 11:38
by Pithikos
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?

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Posted: 07 Nov 2010, 12:35
by Pithikos
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?

Posted: 07 Nov 2010, 13:43
by Niobium
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
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)

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Posted: 07 Nov 2010, 14:21
by Pithikos
But how am I supposed to use that?
I wrote this in the unsynced part:

Code: Select all

function gadget:UpdateCallIn(UpdateRules)
	echo("Update CallIn")
end
And was expecting that the function UpdateRules would update all the time and get an echo "Update CallIn" but nothing happens.

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Posted: 07 Nov 2010, 14:48
by Niobium
Pithikos wrote:But how am I supposed to use that?
I wrote this in the unsynced part:

Code: Select all

function gadget:UpdateCallIn(UpdateRules)
	echo("Update CallIn")
end
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:Update()
   Spring.Echo("Update")
end

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Posted: 09 Nov 2010, 13:53
by Pithikos
Ok thanks it kind of works. But isn't that a bit CPU consuming?