Page 1 of 1

Script works differently on different computers?!

Posted: Wed Nov 14, 2018 11:05 am
by Lukas
Is there something I should know about regarding these two lines of code I'm using?

Line for disabling the 'Paths' checkbox under 'Display quality':

Code: Select all

view:SetQualityFlags(MOHO.clearbit(view:QualityFlags(), MOHO.LDQ_WIREFRAME))
Line for enabling the 'Paths' checkbox under 'Display quality':

Code: Select all

view:SetQualityFlags(MOHO.setbit(view:QualityFlags(), MOHO.LDQ_WIREFRAME))
When I run them on my own computers (both on a Windows 10 machine and on a Macbook Pro running OS X Mojave), they don't always work. (I'm running the code when I press a toolbar button, which always works on all computers, and I'm running the code when I enter and exit frame 0, which used to work in the past (not sure what changed, maybe it was 12.4 or some Windows update, but not anymore)

But here comes the weirdest part, when I'm using my tool on another Windows computer, it works fine when leaving and exiting frame 0. They are both using the exact same Custom Content Folder. Tested it with the same project files too.

Is there something in MOHO.clearbit/setbit that I don't understand that can behave different on different machines in different situations?

Re: Script works differently on different computers?!

Posted: Wed Nov 14, 2018 5:31 pm
by synthsin75
Lukas wrote:Is there something I should know about regarding these two lines of code I'm using?

Line for disabling the 'Paths' checkbox under 'Display quality':

Code: Select all

view:SetQualityFlags(MOHO.clearbit(view:QualityFlags(), MOHO.LDQ_WIREFRAME))
Line for enabling the 'Paths' checkbox under 'Display quality':

Code: Select all

view:SetQualityFlags(MOHO.setbit(view:QualityFlags(), MOHO.LDQ_WIREFRAME))
When I run them on my own computers (both on a Windows 10 machine and on a Macbook Pro running OS X Mojave), they don't always work. (I'm running the code when I press a toolbar button, which always works on all computers, and I'm running the code when I enter and exit frame 0, which used to work in the past (not sure what changed, maybe it was 12.4 or some Windows update, but not anymore)

But here comes the weirdest part, when I'm using my tool on another Windows computer, it works fine when leaving and exiting frame 0. They are both using the exact same Custom Content Folder. Tested it with the same project files too.

Is there something in MOHO.clearbit/setbit that I don't understand that can behave different on different machines in different situations?
I assume that you'd need to provide MOHO.LDQ_WIREFRAME to MOHO.clearbit/MOHO.setbit as a MOHO.bit:

view:SetQualityFlags(MOHO.clearbit(view:QualityFlags(), MOHO.bit(MOHO.LDQ_WIREFRAME)))

And then depending on how you are running it when entering/exiting frame zero, it may be running more than once. So if you're doing a check, like this...

Code: Select all

	if (MOHO.hasbit(view:QualityFlags(), MOHO.bit(MOHO.LDQ_WIREFRAME))) then
		view:SetQualityFlags(MOHO.clearbit(view:QualityFlags(), MOHO.bit(MOHO.LDQ_WIREFRAME)))
	else
		view:SetQualityFlags(MOHO.setbit(view:QualityFlags(), MOHO.bit(MOHO.LDQ_WIREFRAME)))
	end
...it may be working, but being run a different number of times (odd or even) on different systems. You might need to make sure the code only runs once.




If all else fails, there's also doing it brute force, instead of bitwise:

Code: Select all

	local flags = {4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2}
	local qual = moho.view:QualityFlags()
	local tempQual = qual
	for i,v in ipairs(flags) do
		if (tempQual >= v) then
			tempQual = tempQual-v
		end
		if (tempQual == 2) then
			moho.view:SetQualityFlags(qual-2)
			break
		end
		if (i == #flags) and (tempQual ~= 2) then
			moho.view:SetQualityFlags(qual+2)
			break
		end
	end

Re: Script works differently on different computers?!

Posted: Thu Nov 15, 2018 11:27 am
by hayasidist
a bit off topic but … I can't find any write-up of the various MOHO.###bit functions -- any pointers???

Re: Script works differently on different computers?!

Posted: Thu Nov 15, 2018 1:29 pm
by Lukas
Thanks Wes! That stuff goes way over my head. I've tried your brute force variant of the code and the results are the same. It works fine on my colleague's Windows 10 machine, but not on mine.

Here is the code:
http://www.lukaskrepel.nl/temp/ASP/LK_Test.lua (With the tool being active, move in and out of frame 0, the paths checkbox should be true on frame 0, and false on all other frames)
http://www.lukaskrepel.nl/temp/ASP/Debug.lua (I use this as a menu script and use "Debug:Log()" instead of "print" for debugging purposes, feel free to use it)

@hayasidist, I wish I knew where to point...

Re: Script works differently on different computers?!

Posted: Thu Nov 15, 2018 2:21 pm
by hayasidist
dumb question time .. 32 or 64 bit systems??

Re: Script works differently on different computers?!

Posted: Thu Nov 15, 2018 2:28 pm
by Lukas
All are 64 bit systems running the 64 bit version of Moho :)

Re: Script works differently on different computers?!

Posted: Thu Nov 15, 2018 5:44 pm
by synthsin75
hayasidist wrote:a bit off topic but … I can't find any write-up of the various MOHO.###bit functions -- any pointers???
Check the lm_utilities. He made global functions to duplicate iterating bits in Lua, found here: http://lua-users.org/wiki/BitwiseOperators

Re: Script works differently on different computers?!

Posted: Thu Nov 15, 2018 7:22 pm
by synthsin75
Lukas wrote:Thanks Wes! That stuff goes way over my head. I've tried your brute force variant of the code and the results are the same. It works fine on my colleague's Windows 10 machine, but not on mine.

Here is the code:
http://www.lukaskrepel.nl/temp/ASP/LK_Test.lua (With the tool being active, move in and out of frame 0, the paths checkbox should be true on frame 0, and false on all other frames)
http://www.lukaskrepel.nl/temp/ASP/Debug.lua (I use this as a menu script and use "Debug:Log()" instead of "print" for debugging purposes, feel free to use it)
I was wrong about needing MOHO.bit. Just MOHO.LDQ_WIREFRAME is right, as that's all that works when changing other display settings.

Okay, it wasn't working on my computer either, but I found the problem. It should work for you if you disable GPU acceleration in the preferences (not just in the display settings). But this is only a problem with the code in a DrawMe function. If you move it to an OnMouse function, it should work with GPU enabled.

This could be a limitation with DrawMe and GPU (or it might be a bug), but we could really use scripting access to turning GPU on and off.

Re: Script works differently on different computers?!

Posted: Thu Nov 15, 2018 8:27 pm
by Lukas
Oh cool. I'm currently at home on my Macbook, on which it's impossible to disable GPU in the preferences... But I'll check it out tomorrow at work. It sounds promising.

Re: Script works differently on different computers?!

Posted: Thu Nov 15, 2018 9:44 pm
by hayasidist
synthsin75 wrote:
hayasidist wrote:a bit off topic but … I can't find any write-up of the various MOHO.###bit functions -- any pointers???
Check the lm_utilities. He made global functions to duplicate iterating bits in Lua, found here: http://lua-users.org/wiki/BitwiseOperators
Thanks Wes.
synthsin75 wrote:This could be a limitation with DrawMe and GPU (or it might be a bug)...
hmm -- are you saying that DrawMe isn't being invoked properly / at all if GPU is enabled???

Re: Script works differently on different computers?!

Posted: Fri Nov 16, 2018 4:42 am
by synthsin75
hayasidist wrote:
synthsin75 wrote:This could be a limitation with DrawMe and GPU (or it might be a bug)...
hmm -- are you saying that DrawMe isn't being invoked properly / at all if GPU is enabled???
No, DrawMe is definitely being invoked, but no display setting changes take effect with the GPU pref enabled. They change just fine from OnMouse and Run functions, or GPU disabled in the preferences. The thing is that this shows it's working internally:

Code: Select all

print(tostring(MOHO.hasbit(view:QualityFlags(), MOHO.LDQ_WIREFRAME)))
If I add moho:UpdateUI() to DrawMe it works (even with GPU enabled), but it causes the workspace display to be unusable, and when I enable the GPU display quality, it shows the "Show curves" checkbox changing but just flickers the workspace and doesn't actually change the display setting in the menu.


If changing the display settings from a tool, I'd suggest just enabling NonDragMouseMove and placing it in OnMouseMoved.

Re: Script works differently on different computers?!

Posted: Fri Nov 16, 2018 8:29 am
by hayasidist
thanks for the explanation. sounds like a bug to me....

Re: Script works differently on different computers?!

Posted: Fri Nov 16, 2018 11:05 am
by Lukas
Aaahhh, so that's why it was only working when triggering it trough a toolbar button (so HandleMessage would call it). Happy to have this mystery solved. I'll keep the GPU off for now. Weird bug.