PDA

View Full Version : OnDesktopInit() question



Ezio
April 25th, 2018, 23:14
I'd like to set the lighting for clients when they connect, rather than waiting for all to connect then set the lighting.

I figured I could use the OnDesktopInit() event, but now I'm unsure of when this event is triggered or if I'm going to be able to do this.



function onInit()
Interface.onDesktopInit = onDesktopInit;
end
function OnDesktopInit()
Interface.setLighting('FFFFFF', '701919', 'FFFFFF', 'FFFFFF');
end


Possibly, if that is not able to be done, execute the setLighting method when a user connects to the host.

Mortar
April 26th, 2018, 00:40
Isn't easier just to set the lighting before any of your players connect? That way its already set for them as it essentially is your desktop settings that are being transferred to the player clients

Ezio
April 26th, 2018, 00:57
It doesn't work like that. It only sets the lighting for connected clients. So if the GM sets lighting then someone else joins he has to reset. This would be more of an ease of use thing.

Trenloe
April 26th, 2018, 01:19
function onInit()
Interface.onDesktopInit = onDesktopInit;
end
function OnDesktopInit()
Interface.setLighting('FFFFFF', '701919', 'FFFFFF', 'FFFFFF');
end

Have you tried this? There may be timing issues, but it's worth giving it a go - it's not a huge amount of code to test. :)

Ezio
April 26th, 2018, 01:59
I have and it doesn't work or maybe the event triggers too soon or a part isn't actually initialized. I just don't quite know enough about how OnDesttopInit() works.

I did try to replicate getting the character selection window to open and the setup window. Just to get a data point and see if the event is actually being triggered, but that wasn't working either.

Moon Wizard
April 26th, 2018, 02:13
Only the GM can set the lighting, so it has to be initiated on the GM side. If you want to trigger on a user login, then you can do something like:



function onInit()
if (User.isHost)
User.onLogin = onUserLogin;
end
end
function onUserLogin()
Interface.setLighting('FFFFFF', '701919', 'FFFFFF', 'FFFFFF');
end


JPG

Ezio
April 26th, 2018, 12:11
Only the GM can set the lighting, so it has to be initiated on the GM side. If you want to trigger on a user login, then you can do something like:



function onInit()
if (User.isHost) then
User.onLogin = onUserLogin;
end
end
function onUserLogin()
Interface.setLighting('FFFFFF', '701919', 'FFFFFF', 'FFFFFF');
end


JPG

I assumed I would have to use something like this as the GM can only set the lighting, but wasn't sure if that was application level lock or deeper.

I've tried the code you've suggested above Moon, but still no dice. I've even tried just getting a message pumped to chat window when the event fires, but it's not doing that either so I don't know if I'm just not initializing the script in the extension.xml file correctly or what. I'll attach the .ext if you want to take a look at it.

damned
April 26th, 2018, 13:29
Have a look at Trenloes Message of the Day extension. I think it uses the same trigger.

Trenloe
April 26th, 2018, 13:59
Have a look at Trenloes Message of the Day extension. I think it uses the same trigger.
Indeed it does.

But, Ezio is basically using the right code.

@Ezio - the issue is that the calling of your startup script is not valid. You need a "name" with the <script> tag. Change your code extension.xml to:

<script name="MyStartup" file="script\startup.lua" />

Info on the <script> syntax here: https://www.fantasygrounds.com/refdoc/script.xcp

Ken L
April 26th, 2018, 19:00
I've tried the code you've suggested above Moon, but still no dice. I've even tried just getting a message pumped to chat window when the event fires, but it's not doing that either so I don't know if I'm just not initializing the script in the extension.xml file correctly or what. I'll attach the .ext if you want to take a look at it.

Your logic simply isn't executing then. If it's global at <base></base> then it should execute, if it's within an xml, then that xml needs to be active. IE: a window's script attached xml will only execute after the window is opened/launched etc...

A side note for xml element dependent scripts is that that element needs to be active/open for the host, as the script will only be valid for the host. May as well wrap it up in a if User.isHost().

Trenloe
April 26th, 2018, 19:16
Your logic simply isn't executing then.
And the reason for it not executing I posted immediately before your post...

Ken L
April 26th, 2018, 19:41
And the reason for it not executing I posted immediately before your post...

You're only addressing the global case. You can also plug in this logic into a panel or a windowclass which will work, they'll just have to be active first. Panels are special as they're always up as they're part of the desktop menagerie.

I have an automatic light control that responds to the current time that is entirely panel based with no global scripts. The mini-panel is a time advancement hub where I can scroll up/down then click to push time forward or backward and thus auto-triggering light. I similarly use the user login detection mentioned by moon to apply the lighting conditions when users connect so it's a path I've already trodded.

Trenloe
April 26th, 2018, 19:53
You're only addressing the global case.
Yes, I was. Because the OP was using a global case.

As you said "If it's global at <base></base> then it should execute..." Which is what Ezio did - but the syntax was incorrect.

My solution was accurate - your response was partly accurate ("Your logic simply isn't executing then") but then got confusing, without actually giving the solution to the issue. I'm guessing you didn't look at the posted problem extension. Hence why I wanted to make sure Ezio (and you) were aware of the actual solution.

Ezio
April 27th, 2018, 00:33
@Trenloe, your fixed worked. I added in the name parameter and it was setting the lighting!

Thank you for all the assistance @Damned, @Trenloe, @Moon Wizard, and @Ken L.