Setting a variable to NULL?

LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.

Moderators: LCMark, LCfraser

Post Reply
trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Setting a variable to NULL?

Post by trevordevore » Fri Mar 13, 2015 5:46 pm

So now that we have inherited fonts, I need a way of knowing when to override a font, font size, or font style in my widget. I was hoping to be able to set a variable to NULL so that I could know whether or not the value had been set. For font and font style an empty string or list will work just fine. For numbers I would like to use NULL to designate that the size should be inherited. In this case I could use -1 internally, but if my number needed to use negative or positive values then -1 wouldn't work.

Should we be able to set a Number variable to null?
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1212
Joined: Thu Apr 11, 2013 11:27 am

Re: Setting a variable to NULL?

Post by LCMark » Fri Mar 13, 2015 6:02 pm

@trevordevore: I'm not sure I follow the use-case.

The 'my font' patch essentially means that you can get the font as described by the standard (inherited) LiveCode text properties - in particular you cannot define textFont/textSize/textStyle properties of widgets (at the moment at least) because the engine manages those for you. Can you explain a little more about your use-case - it might be that the 'my font' approach is unsuitable.

In terms of representing 'nothing' and numbers - you can use 'optional' types.

Code: Select all

variable tVar is optional number
-- do something to populate tVar
if tVar is undefined then
  -- there is no number there
  put 100 into tVar
else
  -- there is a number there
  put undefined into tVar
end if
-- tVar might be a number or might be undefined
You can check whether optional types contain something by using 'is defined' / 'is not defined' / 'is undefined' / 'is not undefined'.

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Setting a variable to NULL?

Post by trevordevore » Fri Mar 13, 2015 6:23 pm

Thanks for the info on "optional". I had seen that in some lcb code but didn't know what it meant.

As for my font, I was looking for a way to display property inspector elements for textFont, textSize, and textStyle. I was just going to come up with different labels that I would use to override the my font settings if they were present. I see that that is a lousy approach.

Any ideas on how to get the textFont/Size/Style properties into the property inspector for a widget?
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1212
Joined: Thu Apr 11, 2013 11:27 am

Re: Setting a variable to NULL?

Post by LCMark » Fri Mar 13, 2015 7:56 pm

For now you can 'hack' it by putting property definitions in the widget with dummy set/get prop handlers - (there must be an editor you can specify for fonts, because the textFont property on classic controls has one). They won't actually get used as the widget doesn't see any reserved property interactions (except via OnParentPropertyChanged and the syntax designed to get the derived values).

I suspect the Property Inspector has a 'built-in' list somewhere, but as we only 'reserved' the font properties today, it hasn't filtered up to the IDE yet. Also, I'm not entirely sure how the textFont editor is hooked into - the classic controls have it, and everything is dynamically generated so there must be an editor you can set in the metadata of the property.

(I must confess, beyond occasional help with specific things, the IDE changes have been runrevben, runrevelanor, runrevali and runrevgeogia's domain thus I don't know the in-depth details of exactly how it works and puts / references things)

livecodeali
Livecode Staff Member
Livecode Staff Member
Posts: 192
Joined: Thu Apr 18, 2013 2:48 pm

Re: Setting a variable to NULL?

Post by livecodeali » Fri Mar 13, 2015 9:29 pm

Hi Trevor,

If you put

metadata textFont.options is "execute:get the fontNames; sort it"
metadata textFont.editor is "com.livecode.pi.enum"

then I *think* it will work out putting the font options in the property inspector. You might want

metadata textFont.section is "Text"

too, to put it into the appropriate part of the PI.

If those don't work, then there's a bug for us to look at next week :-)

livecodeali
Livecode Staff Member
Livecode Staff Member
Posts: 192
Joined: Thu Apr 18, 2013 2:48 pm

Re: Setting a variable to NULL?

Post by livecodeali » Fri Mar 13, 2015 9:31 pm

Alternatively, (and probably much more easily) you can add all of the properties to the Toolset/resources/supporting_files/property_definitions/com.livecode.interface.classic.widget.txt file.

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Setting a variable to NULL?

Post by trevordevore » Fri Mar 13, 2015 9:51 pm

@livecodeali - I added textFont, textSize, and textStyle to the class.widget.txt file and the Text inspector now shows up for widgets. Not sure if there should be a way in each widget definition to specify this or not, but I'm going to leave it on for my work. Thanks!
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

Post Reply

Return to “LiveCode Builder”