Forged Alliance Forever Forged Alliance Forever Forums 2016-01-17T07:38:46+02:00 /feed.php?f=41&t=11496 2016-01-17T07:38:46+02:00 2016-01-17T07:38:46+02:00 /viewtopic.php?t=11496&p=117860#p117860 <![CDATA[Re: Taking back custom data from ui]]> Statistics: Posted by nine2 — 17 Jan 2016, 07:38


]]>
2016-01-16T23:48:26+02:00 2016-01-16T23:48:26+02:00 /viewtopic.php?t=11496&p=117845#p117845 <![CDATA[Re: Taking back custom data from ui]]>
Here are the steps for tutorial purpose. A How to modify sim and module data from ui.


My goal was to spend skillpoints and increment the armor skill each time i click on ArmorPointsIcon in the ui (in this case economy.lua). My Data are saved in my module TransferDatas.lua.

Economy.lua code [Ui]

Code:
local TD = import('/Mods/Mytestmod/Modules/TransferDatas.lua')


Code:
ArmorPointsIcon.HandleEvent = function(self, event)
         if event.Type == 'ButtonPress' then
            local unit = GetSelectedUnits()
            if unit then
               local _id = unit[1]:GetEntityId()
               local Skpoints = TD.GetProperty(_id,"SkillPoints")-1
               if Skpoints >= 0 then
                  SimCallback( {    Func="OnApplyPoints",
                              Args={ id = _id}
                            }
                           )
               end
            end
         end
      end


SimCallbacks.lua code reference to my module TransferDatas.lua. This is the Bridge that will make all work

Code:
Callbacks.OnApplyPoints = import('/Mods/Mytestmod/Modules/TransferDatas.lua').OnApplyPoints


My module TransferDatas.lua code :

Code:
function OnApplyPoints(Unit)
   -- LOG(repr(Unit))
   local id = Unit.id
   IncProperty(id,"Armor",1)
   IncProperty(id,"SkillPoints",-1)   
end


GetProperty and IncProperty are custom function in my module to Get and Set my custom data. Don't forget to sync theses data to use them in simside.

You can notice that it seems simpler to do not modify my data in the ui (economy.lua) but from the ui in my module TransferDatas.lua.

Hope this may help :)

Statistics: Posted by Franck — 16 Jan 2016, 23:48


]]>
2016-01-15T21:40:14+02:00 2016-01-15T21:40:14+02:00 /viewtopic.php?t=11496&p=117801#p117801 <![CDATA[Taking back custom data from ui]]>
I'm still hard working on my mod, and the data connection between simside (unit.lua) and my module works fine thanks to Myxir's help ;) .

Now, i've got a custom database that the user modify from the ui (in my case the economy.lua by clicking on customs icons).
I know that i need to use callback functions to send data back to my lua module and to the sim side as it said in Myxir's page http://wiki.faforever.com/index.php?tit ... Sim_and_UI.

I'm not particulary familiar with callback function. I know that callback functions are function given by parameters in another function. I saw some of them in the scenarioFramework.lua file but i don't understand their practical use. Do i need to do something in the SimCallbacks.lua file too ?

Can somebody provide the most simple example of code for sending back a custom data content from ui to a mod module and simside ?

Thanks a lot for your help. It's not easy to write something i don't understand fully. I tried several hours without success.

Statistics: Posted by Franck — 15 Jan 2016, 21:40


]]>