Equivalent to LUAUI_DIRNAME for LuaRules directory?

Equivalent to LUAUI_DIRNAME for LuaRules directory?

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

User avatar
Pithikos
Posts: 146
Joined: 26 Dec 2008, 14:26

Equivalent to LUAUI_DIRNAME for LuaRules directory?

Post by Pithikos »

Is there something similar to "LUAUI_DIRNAME" but for LuaRules?
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Post by zwzsg »

Maybe there's none because dir name would be different accross users and LuaRules has to remain synced?
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Post 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.
User avatar
Pithikos
Posts: 146
Joined: 26 Dec 2008, 14:26

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Post 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
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Post 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.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Post by CarRepairer »

Leave all the fonts in your LuaUI folder and add this line to your gadget:

Code: Select all

LUAUI_DIRNAME = 'LuaUI/'
User avatar
Pithikos
Posts: 146
Joined: 26 Dec 2008, 14:26

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Post 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 :/
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Post by zwzsg »

It sounds like the problem is not on line 25, but on some other line, one that uses gl.something
User avatar
Pithikos
Posts: 146
Joined: 26 Dec 2008, 14:26

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Post 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?
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Post by zwzsg »

Yes.

gl. is for graphism, which can't be done in the synced of a gadget. Pastebin the whole gadget?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Post 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.
User avatar
Pithikos
Posts: 146
Joined: 26 Dec 2008, 14:26

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Post 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
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Post 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.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Post 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.
User avatar
Pithikos
Posts: 146
Joined: 26 Dec 2008, 14:26

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Post 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?
User avatar
Pithikos
Posts: 146
Joined: 26 Dec 2008, 14:26

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Post 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
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Post 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)
User avatar
Pithikos
Posts: 146
Joined: 26 Dec 2008, 14:26

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Post 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.
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Post 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
User avatar
Pithikos
Posts: 146
Joined: 26 Dec 2008, 14:26

Re: Equivalent to LUAUI_DIRNAME for LuaRules directory?

Post by Pithikos »

Ok thanks it kind of works. But isn't that a bit CPU consuming?
Post Reply

Return to “Lua Scripts”