someStruct.width "width" Turns Red And Throws Error

Code Sample:
GML:
function someStructConstructor () constructor
{
//...
    width = undefined;
    height = undefined;
//...
}

//Create Event
someStruct = new someStructConstructor();
//...
someStruct.width = bbox_right - x; //Here "width" turns red like it's a built-in constant. Error is thown when attempting to write to variable. "height" does the same.
someStruct.height = bbox_bottom - y;
//...
Obvious solution is to change variable name to _width or something. Is width a built-in constant? I can't find it in the list of built-in constants unless I missed it or wasn't looking in the right place. Has anyone else encountered this?
 

NightFrost

Member
The color is set because both are built into GML. If you start typing anyStringHere. and look at the autocomplete hinting (sometimes you may need to delete the dot and retype it to make the dropdown appear) scrolling down past the builtin variables you can see both names on the differently colored section (mine are orange). They are suggested because GML doesn't do variable typing so it doesn't have any idea what your someStruct is about. I don't recall ever getting errors when using them though. But I tend to capitalize my struct variables (ie Width)so most of the time they'd fly past any pattern matching the IDE does.
 
The color is set because both are built into GML. If you start typing anyStringHere. and look at the autocomplete hinting (sometimes you may need to delete the dot and retype it to make the dropdown appear) scrolling down past the builtin variables you can see both names on the differently colored section (mine are orange). They are suggested because GML doesn't do variable typing so it doesn't have any idea what your someStruct is about. I don't recall ever getting errors when using them though. But I tend to capitalize my struct variables (ie Width)so most of the time they'd fly past any pattern matching the IDE does.
Capitalizing the struct variables is a good idea.
 

TsukaYuriko

☄️
Forum Staff
Moderator
Interesting... It's not throwing an error now. But, width is still turning red.
Red doesn't mean that anything is wrong. It just means the IDE recognizes width as a default variable of some internal struct, just like name and frame. Those are colored red by default. You can change this color in the settings to anything you want if you have an angry bull at home that throws hissy fits every time it sees red. :)

Now, this is not quite intentional, and indeed far from ideal... but given how GML works, it may also not be anything that can really be "fixed" because there's no real way to tell whether a struct references a default struct type or a custom struct type defined by the user. So... rather than displaying for none, it displays for all.
 
Red doesn't mean that anything is wrong. It just means the IDE recognizes width as a default variable of some internal struct, just like name and frame. Those are colored red by default. You can change this color in the settings to anything you want if you have an angry bull at home that throws hissy fits every time it sees red. :)

Now, this is not quite intentional, and indeed far from ideal... but given how GML works, it may also not be anything that can really be "fixed" because there's no real way to tell whether a struct references a default struct type or a custom struct type defined by the user. So... rather than displaying for none, it displays for all.

Code completion lists width as a "BuiltIn TrackEvalNode"

Again, this was 2 am my time last night and I was afraid I couldn't use the variable name.
 
Top