PDA

View Full Version : Module using "Session.isHost" gets nil?



celestian
March 4th, 2021, 21:07
I've a very simple extension (https://www.fantasygrounds.com/forums/showthread.php?43751-CoreRPG-based-On-Demand-Manual-Dice-(DM-only)&p=389020&viewfull=1#post389020) that lets the DM, on demand, get the "manual roll" menu popup. However I've noticed that "Session.isHost" within this extension doesn't work on CoreRPG and 5e? I tried this with the Live and Test channels. Both give me "nil"



Runtime Notice: s'manager_action_attack_onDemandManualDice.lua' | s'adnd_roll' | nil | bTRUE


Here is the specific code section. I do the same "Session.isHost" in my ruleset and it works.



function onInit()
-- replace default roll with adnd_roll to allow
-- control-dice click to prompt for manual roll
Debug.console("manager_action_attack_onDemandManualDice.lua","onInit","Initializing");
ActionsManager.roll = adnd_roll;
--
end

-- replace default roll with adnd_roll to allow
-- control-dice click to prompt for manual roll
function adnd_roll(rSource, vTargets, rRoll, bMultiTarget)

-- Debug.console("manager_action_attack_onDemandManualDice.lua","adnd_roll",rSource,vTargets,rRoll,bMultiTarget);

if #(rRoll.aDice) > 0 then

Debug.console("manager_action_attack_onDemandManualDice.lua","adnd_roll",Session.isHost,Input.isControlPressed());

if not rRoll.bTower and (OptionsManager.isOption("MANUALROLL", "on") or (Session.isHost and Input.isControlPressed())) then
local wManualRoll = Interface.openWindow("manualrolls", "");
wManualRoll.addRoll(rRoll, rSource, vTargets);
else
local rThrow = ActionsManager.buildThrow(rSource, vTargets, rRoll, bMultiTarget);
Comm.throwDice(rThrow);
end
else
if bMultiTarget then
ActionsManager.handleResolution(rRoll, rSource, vTargets);
else
ActionsManager.handleResolution(rRoll, rSource, { vTargets });
end
end
end


See the same behavior in FGU and FGC. (Yes, I tested w/o BetterMenus also :")

https://i.imgur.com/LUKXHti.png

Varsuuk
March 4th, 2021, 21:37
Fast check in my extension to MoreCore for S&W - yup, same result:
Runtime Notice: s'IS HOST=' | nil

When I threw it into a roller method for quick test:

function createRoll(sParams)
Debug.console("IS HOST=", Session.isHost)
local rRoll = {}
...


This is with CLASSIC though and a couple months old version too. So if it is new, my input if meaningless ;)

Varsuuk
March 4th, 2021, 22:00
To throw further info in the pot -

I searched on isHost in CORE to see if my version uses it. Found some and where it was I said... hmmm... it really needs to work there.

Tested by adding this to Core's manager_combat:




function onCharDelete(nodeChar)
Debug.console("delete IS_HOST=", Session.IsHost)
if not Session.IsHost then
return;
end
...


and it prints in console when I delete a char I added to the CT previously:

Runtime Notice: s'delete IS_HOST=' | bTRUE


So... visibility? I'm curious and will look if no answer is posted here by time off from work and eat dinner and can look at this stuff again :)

Kelrugem
March 4th, 2021, 22:26
You have a typo, it is a very subtle problem: Session.IsHost, not Session.isHost :) The i has to be capital :)

bmos
March 4th, 2021, 22:37
You have a typo, it is a very subtle problem: Session.IsHost, not Session.isHost :) The i has to be capital :)The number of times I have made this mistake... 🤦

celestian
March 4th, 2021, 22:47
You have a typo, it is a very subtle problem: Session.IsHost, not Session.isHost :) The i has to be capital :)

OMG, I must have search/replaced using .IsHost but did .isHost in my extensions ;( .... also, why is it IsHost and not isHost ;(

Thanks for catching it.

bmos
March 4th, 2021, 22:55
OMG, I must have search/replaced using .IsHost but did .isHost in my extensions ;( .... also, why is it IsHost and not isHost ;(

Thanks for catching it.isHost was the style when it was a function, but now it's a global variable.

celestian
March 4th, 2021, 22:57
isHost made sense when it was a function, but now it's a global variable.

I don't code by trade so perhaps I have a gap in my knowledge here but... Why would naming change in that case. I don't think I've ever noticed that sorta thing in JS/lua/python/perl/c# that I recall but... as I said, I don't "code" for a living.

bmos
March 4th, 2021, 23:56
I don't code by trade so perhaps I have a gap in my knowledge here but... Why would naming change in that case. I don't think I've ever noticed that sorta thing in JS/lua/python/perl/c# that I recall but... as I said, I don't "code" for a living.

Typically that sort of thing is supposed to make code more clear.
Like this (https://www.fantasygrounds.com/forums/showthread.php?66350-New-Programming-Style-Programming-Convention).

Varsuuk
March 4th, 2021, 23:59
OMG - didn't see that lol - since I by habit use camel-case.

The casing preferences (speaking from old days - not up with current languages) was usually (ignoring the old Microsoft so-called-Hungarian notation system - an abomination - not to be confused with Moon's Hungarian because 1) it is more sensible than ulongVarName or what have you super specific stuff that actually CHANGED as bits changed and they could not DARE go back and change it since it's compiled and APIs with DLLs etc...but I digress - it always annoyed me when something that is an int was called a long etc....) camel case for C++ variables and methods with Pascal case for Classes and CTORs (and properties in languages with such things) - Pascal case I cannot recall who primarily used it (besides one assumes Pascal but that was 80s, I remember none of that) for members.

I personally stuck to camel with Pascal only for classes/class-like things and by extension CTORs because they have to match.

Varsuuk
March 5th, 2021, 00:00
And Celestian... with all you've created and added to FG... the software engineering world is probably lesser for you NOT having it as a Day-Job ;P

celestian
March 5th, 2021, 02:53
OMG - didn't see that lol - since I by habit use camel-case.


Ditto, thats why I was confused ;)

Varsuuk
April 18th, 2021, 22:00
I'm going over the many CoreRPG changes since my last update and I saw a place where User.isHost() was changed to Session.IsHost so it reminded me to search for all my User.isHost() s. in the code to replace it.

Then noticed a User.isLocal() and wondered if there was an analogous (as I suspect) one from Session. But I could not find Session in base.xml or doing a search on the Developer wiki.

Where is Session defined?

bmos
April 18th, 2021, 22:02
I'm going over the many CoreRPG changes since my last update and I saw a place where User.isHost() was changed to Session.IsHost so it reminded me to search for all my User.isHost() s. in the code to replace it.

Then noticed a User.isLocal() and wondered if there was an analogous (as I suspect) one from Session. But I could not find Session in base.xml or doing a search on the Developer wiki.

Where is Session defined?Session is part of the base FantasyGrounds API: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644556/API%2B-%2BPackages

Varsuuk
April 18th, 2021, 22:12
Thanks, I was looking at that page, but I don't see Session. I see User however.

45860

I tried typing Session in the search box on that screen but I expected it to appear at same level as User/Interface etc if it is such.

bmos
April 18th, 2021, 22:15
Thanks, I was looking at that page, but I don't see Session. I see User however.

45860

I tried typing Session in the search box on that screen but I expected it to appear at same level as User/Interface etc if it is such.Yes, the wiki is a bit behind.

Trenloe
April 18th, 2021, 22:16
See the info on the changes in February here: https://www.fantasygrounds.com/forums/showthread.php?65561-2020-02-Ruleset-Updates&p=574220&viewfull=1#post574220

Varsuuk
April 18th, 2021, 22:22
EDIT: Just saw Trenloe's post - going there enow, THANKS!

Ah - OK - so how do I find out what is in it or avail?

Is it in some post somewhere in beta/release areas?

I guess I can do a search on "Session" in CoreRPG to see some of the exported names, but what I was trying to do was replace all my "dated"? User.isHost() to SessionIsHost then I discovered User.isLocal() in a boolean check related to isHost() check so went to verify this also existed which made me wonder what else. At first I thought it was a CoreRPG thing but now get it.

But without documentation or a ChangeList (which I assume was posted but I don't regularly read forums like I'd like to) , I don't know what to do with this new thing.

Moon Wizard
April 18th, 2021, 22:27
Session package variables

IsHost [bool]
IsLocal [bool]
VersionMajor [#][X = client release (X.#.#)]
VersionMinor [#][X = client release (#.X.#)]
VersionRelease [#][X = client release (#.#.X)]
CampaignName [string]
RulesetName [string]
UserName [string][FG account name]

Varsuuk
April 18th, 2021, 22:34
Thank you all, I just finished my review of everything up to Sidebar (did some previously I inferred from other extensions, now checking this list) - which I was going to lookup anyhow because my rectangular buttons went away on latest update (I was using the 2E/OSR style for quite some time, so I need to look at why it changed. The functionality is still there, I see the labels on a translucent background is all)

Seeing the above, I replaced the isLocal's as well. Thanks.

---
Done. Turns out the majority of the "hits" were in my MoreCore. I realized that after changing probably half of them. I undid my changes (although, would be glad to do them and submit to Damned, it's just easy one for one changes but be glad to do the boring work for you Damned, if you say so.)

Varsuuk
April 18th, 2021, 22:35
Session package variables

IsHost [bool]
IsLocal [bool]
VersionMajor [#][X = client release (X.#.#)]
VersionMinor [#][X = client release (#.X.#)]
VersionRelease [#][X = client release (#.#.X)]
CampaignName [string]
RulesetName [string]
UserName [string][FG account name]



Plus - thank you for this. Adding it to my OneNote until it is in regular docs so I don't forget the available resources.

Moon Wizard
April 19th, 2021, 20:56
Added to wiki here:
https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/1470234625/Session

Regards,
JPG

bmos
April 19th, 2021, 23:20
Awesome :)
It might also be a good idea to edit User, since it still tells about User.isHost().

Moon Wizard
April 20th, 2021, 03:19
User.isHost() is still available and valid. I just decided to create a new package of just system variables; so that there was no marshalling needed to get those common pieces of data.

Regards,
JPG

bmos
April 20th, 2021, 12:08
User.isHost() is still available and valid. I just decided to create a new package of just system variables; so that there was no marshalling needed to get those common pieces of data.

Regards,
JPGoh! good to know. thanks!

Jiminimonka
December 2nd, 2023, 17:10
User.isHost() is still available and valid. I just decided to create a new package of just system variables; so that there was no marshalling needed to get those common pieces of data.

Regards,
JPG

Seems to not be valid anymore from the error reports popping up for extensions after the latest update. Session.IsHost is the fix for that (I think)

Moon Wizard
December 2nd, 2023, 18:24
User.isHost() is still a valid API; and Session.IsHost is a mirror variable that doesn't require an API call just a variable check.

The one you referred to on Discord was User.isLocal(), which has gone away. It was an old FG Classic API that always returned false in FGU and is now gone.

Regards,
JPG