Asset - Extension Flags *UPDATE*

ZeDuval

Member


UPDATE: v2.0.2; New:

  • Last version included as a rollback-possibility
  • Clearer seperation between global and local Flags
  • Reduced amount of macros to use
  • Added possibility to access local Flags of one object from another
  • Added shortcut-functions that are very useful if Flag system is intensively used
Flags provides an easy and intuitive way to structure your code. It takes care of all boolean values that you would normally store in variables in order to activate/deactivate specific parts of your code. You can enable the flag-system for single objects, or instances and also use the global flag-system. By using normal variables as flags(true,false), you need to initially set all of them to a start-value. You don't need to do this using Flags. Just use as many as you like as conditions and flip them when the time is ripe.

In the Create - Event of the object obj_abc use...
Code:
flag_local();
...to initialize the local_flag-system for this object.

Wherever you want inside this object, use...
Code:
if flag_local("some_word"){
  // only happens if this local flag is true
}
to use the flag as a boolean condition. You can do this without having set the flag to an initial value, which is automatically false/0.

To set a flag as true, use...
Code:
flag_local("some_word",true);
...or...
Code:
flag_local("some_word",1);
To set a flag as false, use...
Code:
flag_local("some_word",false);
...or...
Code:
flag_local("some_word",0);
To flip(toggle) a flag as from false to true or from true to false, use...
Code:
flag_local("some_word",flip);
...or...
Code:
flag_local("some_word",2);
It is now possible to access a local flag of one object from another, like this...
Code:
abc = instance_create(0,0,obj_abc); // saving a reference of an object instance to the variable abc, whereas obj_abc is an object where the local flag system is initialized!
local_flag(abc,"some_word",flip);
There is one global flag system, that get's automatically initialized. It works the same way, the only difference is that you use...
Code:
if flag_global("any_word"){
  // only happens if this global flag is true
}
flag_global("any_word",true);
flag_global("any_word",1);
flag_global("any_word",false);
flag_global("any_word",0);
flag_global("any_word",flip);
flag_global("any_word",2);
There are two shortcut-functions you can use:
Code:
FL() // instead of flag_local()
FG() // instead of flag_global()

Tested for following export modules: Windows, Windows(YYC), HTML5.
 
Last edited:
S

Salvakiya

Guest
does not seem to work for me... I get unknown function or script ic
 
R

Rukola

Guest
This seems interesting, but what is it used for? From what I gather.. it's a variety on normal variables, are they not?
 

ZeDuval

Member
Easily the biggest advantage over normal vars is the following: With vars as "flags" they have the value true(1) or false(0). When the execution of a codeblock is dependent on the vars value, it gets checked for having the value true or false. This means that the var must first be initialized to one of the two values, otherwise the "var read before set" error gets thrown.

The approach with Flags is that it checks whether the flags value(string or real) does exist(=true/1) or does not exist(=false/0) within a list. No need to initially initialize(yo dawg) anything. Just use the flag xy as a condition and flip it at some point.

Cleaner code(imo), that's less prone to generate errors. The usefullness grows with the quantity of the code within an object and with the size of the project in general, and also with the amount of conditional dependencies, I guess. Maybe it depends on personal coding style, too. I, for example, have a hierarchy of objects, where few objects control many - and for that I usually need quite a few conditions to properly structure everything.
 

ZeDuval

Member
Hello everyone,

as I'm about to publish some new assets in the near future, I decided to update my current assets based on my own usage-experience from the past months. Flags now offers the possibility to access local flags of an object from another object!
I changed some parts of this asset and also some function names. If you already use this asset, you will have to make some changes. I included the last version of this asset as an included file for everyone who updated this asset but doesn't want to make those changes!

Let me know if you encounter any bugs or if you have a suggestion!
 
Top