Forged Alliance Forever Forged Alliance Forever Forums 2017-05-22T08:15:43+02:00 /feed.php?f=41&t=14601 2017-05-22T08:15:43+02:00 2017-05-22T08:15:43+02:00 /viewtopic.php?t=14601&p=149370#p149370 <![CDATA[Re: Broken mod]]> Statistics: Posted by crispweed — 22 May 2017, 08:15


]]>
2017-05-22T05:50:56+02:00 2017-05-22T05:50:56+02:00 /viewtopic.php?t=14601&p=149362#p149362 <![CDATA[Re: Broken mod]]>
viewtopic.php?f=2&t=10021&hilit=downlord

Statistics: Posted by Uveso — 22 May 2017, 05:50


]]>
2017-05-21T09:03:48+02:00 2017-05-21T09:03:48+02:00 /viewtopic.php?t=14601&p=149332#p149332 <![CDATA[Re: Broken mod]]>
Uveso wrote:
PS: i did not test it, but if you want to upload the mod into the vault you need to change the url inside your mod_info.lua: url = "upcoder.com"
Use something with http on start like this:
Code:
url = "http://forums.faforever.com/viewtopic.php?f=41&t=13764"



Nope, tried, this, still can't seem to get this to upload. :(

Statistics: Posted by crispweed — 21 May 2017, 09:03


]]>
2017-05-21T08:50:00+02:00 2017-05-21T08:50:00+02:00 /viewtopic.php?t=14601&p=149328#p149328 <![CDATA[Re: Broken mod]]>
Uveso wrote:
4. paste this into the file buildmode.lua:
Code:
local OldToggleBuildMode = ToggleBuildMode

function ToggleBuildMode()
    -- first execute the original function
    OldToggleBuildMode()
    -- now set shownormals depending on BuildMode
    if trackingMasterControl != nil then
        ConExecute("ren_shownormals true")
    else
        ConExecute("ren_shownormals false")
    end
end


We are now "hooking" the function ToggleBuildMode() inside buildmode.lua

Yep, just checked this, and this looks to work perfectly, also!
(When I tried something like this before (hooking ToggleBuildMode()), it only seemed to catch the toggle *in* to build mode.
But I guess I must have done something stupid around the IsInBuildMode test..)

Uveso wrote:
Just a smal note: You should change your Mod-UID inside mod_info.lua if you change the version number.
Ths way its much clearer that we have a new mod (version)

Ok, yep, was wondering exactly what I was supposed to do there.

Uveso wrote:
PS: i did not test it, but if you want to upload the mod into the vault you need to change the url inside your mod_info.lua: url = "upcoder.com"
Use something with http on start like this:

And yes, we did have issues with the vault upload. :)
Will try this, also.
Cheers!

Statistics: Posted by crispweed — 21 May 2017, 08:50


]]>
2017-05-21T02:13:19+02:00 2017-05-21T02:13:19+02:00 /viewtopic.php?t=14601&p=149315#p149315 <![CDATA[Re: Broken mod]]> This way we don't have any lag or are wasting cpu/memory:

1. Please delete the folder modules and the file beat_function.lua from your mod.
2. Delete the file gamemain.lua from \mods\MakeBuildModeMoreVisible\hook\lua\ui\game
3. create a new file named buildmode.lua inside the folder \mods\MakeBuildModeMoreVisible\hook\lua\ui\game
4. paste this into the file buildmode.lua:
Code:
local OldToggleBuildMode = ToggleBuildMode

function ToggleBuildMode()
    -- first execute the original function
    OldToggleBuildMode()
    -- now set shownormals depending on BuildMode
    if trackingMasterControl != nil then
        ConExecute("ren_shownormals true")
    else
        ConExecute("ren_shownormals false")
    end
end


We are now "hooking" the function ToggleBuildMode() inside buildmode.lua

Just a smal note: You should change your Mod-UID inside mod_info.lua if you change the version number.
Ths way its much clearer that we have a new mod (version)

Here the new mod with hook instead of onbeat :)
MakeBuildModeMoreVisible-V3.zip

PS: i did not test it, but if you want to upload the mod into the vault you need to change the url inside your mod_info.lua: url = "upcoder.com"
Use something with http on start like this:
Code:
url = "http://forums.faforever.com/viewtopic.php?f=41&t=13764"


PPS. If you use this url, you should update your first post with the new mod version. Just edit the first post. (And delete your 3 post :))

Statistics: Posted by Uveso — 21 May 2017, 02:13


]]>
2017-05-21T01:42:42+02:00 2017-05-21T01:42:42+02:00 /viewtopic.php?t=14601&p=149314#p149314 <![CDATA[Re: Broken mod]]>
nice work :)

We could improve the memory usage and speed of this function if we don't import "buildmode.lua" on every beat.

We set BuildMode to nil, and ask on the first beat if it is nil and import it only once:
Code:
local wasInBuildMode = nil -- this makes no assumption about start state, but triggers one toggle at the start, regardless (which can be a problem when using toggling console functions)
--local wasInBuildMode = false -- assumes this is off at start, but then avoids an initial toggle at the start
local BuildMode = nil
local isInBuildMode = nil

function BeatFunction()
    if BuildMode == nil then
        BuildMode = import('/lua/ui/game/buildmode.lua')
    end
    isInBuildMode = BuildMode.IsInBuildMode()
    if wasInBuildMode ~= isInBuildMode then
        --ConExecute("ren_bloom " .. tostring(isInBuildMode))
        ConExecute("ren_shownormals " .. tostring(isInBuildMode))
        --ConExecute("ren_ShowSkeletons") -- this just toggles, it seems, regardless of any bool argument
    end
    wasInBuildMode = isInBuildMode
end

Statistics: Posted by Uveso — 21 May 2017, 01:42


]]>
2017-05-20T14:09:18+02:00 2017-05-20T14:09:18+02:00 /viewtopic.php?t=14601&p=149265#p149265 <![CDATA[Re: Broken mod]]>
Thank you for all this info!

Thanks to this, I have been able to solve the issue now. :)

The solution was, (based on what you said about gamestates), to move the buildmode.lua import actually inside the beatfunction itself.
(So I guess this means that buildmode.lua is now imported on first beat, as opposed to on gamemain import.)

An updated, fixed, version of the mod is attached, in case you are interested.

So this still uses the beat function setup.

It's very interesting to know about the possibility for the ForkThread based alternative, but in this case I definitely prefer to get immediate feedback, where that is possible, without any delay.

Statistics: Posted by crispweed — 20 May 2017, 14:09


]]>
2017-05-20T11:24:43+02:00 2017-05-20T11:24:43+02:00 /viewtopic.php?t=14601&p=149257#p149257 <![CDATA[Re: Broken mod]]>
yes you are right, function init() will only be called once on gamestart.
If you want a continous beat, you can add a forked thread.

In this case you can use this as gamemain.lua:
Code:
local originalCreateUI = CreateUI
   
function CreateUI(isReplay)
    originalCreateUI(isReplay)
    if not isReplay then
        local modFolder = 'MakeBuildModeMoreVisible'
        import('/mods/' .. modFolder .. '/modules/beat_function.lua').Init()
    end
end


And here is the forked thread script for beat_function.lua:
Code:
function Init()
    local BeatThread = ForkThread(BeatFunction)
end

function BeatFunction()
    local BuildMode = import('/lua/ui/game/buildmode.lua')
    local wasInBuildMode = false -- we assume this is off at start, and this avoids an initial toggle of render settings
    while true do
        local isInBuildMode = BuildMode.IsInBuildMode()
        if wasInBuildMode ~= isInBuildMode then
            ConExecute("ren_bloom " .. tostring(isInBuildMode))
            ConExecute("ren_shownormals " .. tostring(isInBuildMode))
            --ConExecute("ren_ShowSkeletons") -- this just toggles, it seems, regardless of any bool argument
        end
        wasInBuildMode = isInBuildMode
        WaitSeconds(0.5)
    end
end

Statistics: Posted by Uveso — 20 May 2017, 11:24


]]>
2017-05-20T08:29:09+02:00 2017-05-20T08:29:09+02:00 /viewtopic.php?t=14601&p=149251#p149251 <![CDATA[Re: Broken mod]]>
Uveso wrote:
Because i dont know from this line, what you are try to do here, but the right syntax would be:
Code:
local buildmode = import('/lua/ui/game/buildmode.lua')


Actually, that's exactly what the code was doing, originally, but I cut this down to just the import, to make a minimal repeat case.

(Have a look at the code for the original mod, which I posted here:
http://forums.faforever.com/viewtopic.php?f=41&t=13764)

Uveso wrote:
And copy this into Whatever.lua:

Code: Select all
function Init()
local buildmode = import('/lua/ui/game/buildmode.lua')
local value = buildmode.IsInBuildMode()
if value then
LOG("true")
else
LOG("false")
end
end

It seems like this would only happen once though, if I understand correctly?
(Although I didn't actually test this out, yet.)

Seems like, for this mod to work, I either have to have a 'beat function' (which is how the original mod worked), or else hook into the actual state toggle event in buildmode.lua.

I had a go at that, also, (hooking into the state toggle event), and that may be a workable solution (although, while it is easy to hook the toggle _into_ build mode, it looks messier to hook the toggle back out).
But I'd quite like to understand a bit more about the problem I am working around, nevertheless. :(

Statistics: Posted by crispweed — 20 May 2017, 08:29


]]>
2017-05-20T04:31:27+02:00 2017-05-20T04:31:27+02:00 /viewtopic.php?t=14601&p=149237#p149237 <![CDATA[Re: Broken mod]]>
Code:
import('/lua/ui/game/buildmode.lua')
(This will load AND execute the whole buildmode.lua file, and you are in the wrong gamestate to do so (state->m_rootState == m_state))

Because i dont know from this line, what you are try to do here, but the right syntax would be:
Code:
local buildmode = import('/lua/ui/game/buildmode.lua')


Now if you want to execute a function like "IsInBuildMode()" from buildmode.lua type:
Code:
local value = buildmode.IsInBuildMode()


As i said, i dont know what you are making there and if this helps.

To start copy this into gamemain.lua:
Code:
do
    -- when this script loads, get the original CreateUI function
    local originalCreateUI = CreateUI
    -- now we hook the CreateUI function
    function CreateUI(isReplay)
        -- call the original function first to set up the rest of the game UI
        originalCreateUI(isReplay)
        -- import the files, unless we're in a replay
        if not isReplay then
            import('/mods/RepeatImportProblem/Whatever.lua').Init()
        end
    end
   
end


now create an empty file called "Whatever.lua":
Code:
/mods/RepeatImportProblem/Whatever.lua


And copy this into Whatever.lua:
Code:
   function Init()
        local buildmode = import('/lua/ui/game/buildmode.lua')
        local value = buildmode.IsInBuildMode()
        if value then
            LOG("true")
        else
            LOG("false")
        end
   end


Maybe you can start from there.

Statistics: Posted by Uveso — 20 May 2017, 04:31


]]>
2017-05-19T16:40:36+02:00 2017-05-19T16:40:36+02:00 /viewtopic.php?t=14601&p=149193#p149193 <![CDATA[Broken mod]]>
I'm struggling a bit with one of my mods, which seems to have been broken by recent patches.

It's the 'MakeBuildModeMoreVisible' mini-mod I posted here: http://forums.faforever.com/viewtopic.php?f=41&t=13764

There is actually very little to this mod.
(It just registers a beat function which perfoms a console action on changes to the state indicated by IsInBuildMode().)
But this now crashes the game during startup ('in transit'), when activated.
(A debug message comes up, with the last lines of the log, but this doesn't seem to give much in the way of useful clues about why it is crashing, or else I don't understand enough to get any clues from this.)

I cut it down to just one line of lua, while still repeating the issue, and a minimal repeat case is attached.

This now just hooks 'lua/ui/game/gamemain.lua', and adds a single line with "import('/lua/ui/game/buildmode.lua')".

For what it's worth, the error text I get follows:

Code:
Unhandled exception:

state->m_rootState == m_state

Program : C:\ProgramData\FAForever\bin\ForgedAlliance.exe
Cmd line arguments :

Callstack:
   Unknown symbol (address 0x008d462c)

Last 100 lines of log...

warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(37): in function `import'
warning:         ...a\faforever\gamedata\lua.nx2\lua\ui\game\economy.lua(16): in main chunk
warning:         [C]: in function `doscript'
warning:         [C]: in function `pcall'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(48): in function `import'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(37): in function `import'
warning:         ...forever\gamedata\lua.nx2\lua\ui\game\missiontext.lua(19): in main chunk
warning:         [C]: in function `doscript'
warning:         [C]: in function `pcall'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(48): in function `import'
warning:         ...gramdata\faforever\gamedata\lua.nx2\lua\usersync.lua(127): in function <...gramdata\faforever\gamedata\lua.nx2\lua\usersync.lua:90>
warning:         ...gramdata\faforever\gamedata\lua.nx2\lua\usersync.lua(383): in function `OnSync'
warning:         [string "OnSync()"](1): in main chunk
warning: ...alliance\gamedata\mohodata.scd\lua\system\import.lua(37): Error importing '/lua/ui/game/gamemain.lua'
warning: stack traceback:
warning:         [C]: in function `error'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(52): in function `import'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(37): in function `import'
warning:         ...a\faforever\gamedata\lua.nx2\lua\ui\game\economy.lua(16): in main chunk
warning:         [C]: in function `doscript'
warning:         [C]: in function `pcall'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(48): in function `import'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(37): in function `import'
warning:         ...forever\gamedata\lua.nx2\lua\ui\game\missiontext.lua(19): in main chunk
warning:         [C]: in function `doscript'
warning:         [C]: in function `pcall'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(48): in function `import'
warning:         ...gramdata\faforever\gamedata\lua.nx2\lua\usersync.lua(127): in function <...gramdata\faforever\gamedata\lua.nx2\lua\usersync.lua:90>
warning:         ...gramdata\faforever\gamedata\lua.nx2\lua\usersync.lua(383): in function `OnSync'
warning:         [string "OnSync()"](1): in main chunk
warning: ...alliance\gamedata\mohodata.scd\lua\system\import.lua(37): Error importing '/lua/ui/game/economy.lua'
warning: stack traceback:
warning:         [C]: in function `error'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(52): in function `import'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(37): in function `import'
warning:         ...forever\gamedata\lua.nx2\lua\ui\game\missiontext.lua(19): in main chunk
warning:         [C]: in function `doscript'
warning:         [C]: in function `pcall'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(48): in function `import'
warning:         ...gramdata\faforever\gamedata\lua.nx2\lua\usersync.lua(127): in function <...gramdata\faforever\gamedata\lua.nx2\lua\usersync.lua:90>
warning:         ...gramdata\faforever\gamedata\lua.nx2\lua\usersync.lua(383): in function `OnSync'
warning:         [string "OnSync()"](1): in main chunk
warning: Error running lua command: ...gramdata\faforever\gamedata\lua.nx2\lua\usersync.lua(127): Error importing '/lua/ui/game/missiontext.lua'
         stack traceback:
            [C]: in function `error'
            ...alliance\gamedata\mohodata.scd\lua\system\import.lua(52): in function `import'
            ...gramdata\faforever\gamedata\lua.nx2\lua\usersync.lua(127): in function <...gramdata\faforever\gamedata\lua.nx2\lua\usersync.lua:90>
            ...gramdata\faforever\gamedata\lua.nx2\lua\usersync.lua(383): in function `OnSync'
            [string "OnSync()"](1): in main chunk
debug: Loading module '\000/lua/ui/game/gamemain.lua\000'
info: Hooked /lua/ui/game/gamemain.lua with /mods/ui-party/hook/lua/ui/game/gamemain.lua
info: Hooked /lua/ui/game/gamemain.lua with /mods/reminder/hook/lua/ui/game/gamemain.lua
info: Hooked /lua/ui/game/gamemain.lua with /mods/notify/hook/lua/ui/game/gamemain.lua
info: Hooked /lua/ui/game/gamemain.lua with /mods/supremeeconomy/hook/lua/ui/game/gamemain.lua
info: Hooked /lua/ui/game/gamemain.lua with /mods/simpleridleengineersandfactories/hook/lua/ui/game/gamemain.lua
info: Hooked /lua/ui/game/gamemain.lua with /mods/repeatimportproblem/hook/lua/ui/game/gamemain.lua
info: Hooked /lua/ui/game/gamemain.lua with /mods/autoharvest/hook/lua/ui/game/gamemain.lua
info: Hooked /lua/ui/game/gamemain.lua with /mods/common/hook/lua/ui/game/gamemain.lua
debug: Loading module '\000/lua/ui/game/buildmode.lua\000'
info: Hooked /lua/ui/game/buildmode.lua with /mods/makebuildmodemorevisible/hook/lua/ui/game/buildmode.lua
debug: Loading module '\000/lua/ui/game/construction.lua\000'
info: Hooked /lua/ui/game/construction.lua with /mods/ui-party/hook/lua/ui/game/construction.lua
info: Hooked /lua/ui/game/construction.lua with /mods/notify/hook/lua/ui/game/construction.lua
warning: ...orever\gamedata\lua.nx2\lua\ui\game\construction.lua(83): Attempt to set attribute 'HandleEvent' on nil
warning: stack traceback:
warning:         [C]: in function `error'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\config.lua(12): in function <...alliance\gamedata\mohodata.scd\lua\system\config.lua:11>
warning:         ...orever\gamedata\lua.nx2\lua\ui\game\construction.lua(83): in main chunk
warning:         [C]: in function `doscript'
warning:         [C]: in function `pcall'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(48): in function `import'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(37): in function `import'
warning:         ... alliance\gamedata\lua.scd\lua\ui\game\buildmode.lua(13): in main chunk
warning:         [C]: in function `doscript'
warning:         [C]: in function `pcall'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(48): in function `import'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(37): in function `import'
warning:         ...\faforever\gamedata\lua.nx2\lua\ui\game\gamemain.lua(1212): in main chunk
warning:         [C]: in function `doscript'
warning:         [C]: in function `pcall'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(48): in function `import'
warning: ...alliance\gamedata\mohodata.scd\lua\system\import.lua(37): Error importing '/lua/ui/game/construction.lua'
warning: stack traceback:
warning:         [C]: in function `error'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(52): in function `import'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(37): in function `import'
warning:         ... alliance\gamedata\lua.scd\lua\ui\game\buildmode.lua(13): in main chunk
warning:         [C]: in function `doscript'
warning:         [C]: in function `pcall'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(48): in function `import'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(37): in function `import'
warning:         ...\faforever\gamedata\lua.nx2\lua\ui\game\gamemain.lua(1212): in main chunk
warning:         [C]: in function `doscript'
warning:         [C]: in function `pcall'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(48): in function `import'
warning: ...alliance\gamedata\mohodata.scd\lua\system\import.lua(37): Error importing '/lua/ui/game/buildmode.lua'
warning: stack traceback:
warning:         [C]: in function `error'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(52): in function `import'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(37): in function `import'
warning:         ...\faforever\gamedata\lua.nx2\lua\ui\game\gamemain.lua(1212): in main chunk
warning:         [C]: in function `doscript'
warning:         [C]: in function `pcall'
warning:         ...alliance\gamedata\mohodata.scd\lua\system\import.lua(48): in function `import'
warning: Error importing /lua/ui/game/gamemain.lua:
         Error importing '/lua/ui/game/gamemain.lua'
         stack traceback:
            [C]: in function `error'
            ...alliance\gamedata\mohodata.scd\lua\system\import.lua(52): in function `import'
warning: Error running '/lua/ui/game/gamemain.lua:OnBeat': attempt to index a nil value
         stack traceback:


I'm kind of stuck, at this point, since I don't really know enough about lua, or the import mechanism to chase this down further. :(

Is it maybe a case of circular imports, or something like that?

Can someone else check if they get the same issue, either with the original mod, or with this minimal repeat case mod?

Any ideas or suggestions?

Statistics: Posted by crispweed — 19 May 2017, 16:40


]]>