Creating objects from the script

Started by fireapache, Tue 26/07/2011 03:52:48

Previous topic - Next topic

fireapache

Hi, folks, i have a question! How can i create a GUI and an object directly from the script?

The same resolution can be applied to an array with objects or GUIs?

I thought it would be something like this:
Code: ags

GUI* SomeName = new GUI();

RickJ

AFIK game elements such as characters, objects, guis, etc can't be dynamically created at runtime.   The exceptions I am aware of are dynamic sprites and dynamically sized arrays.

However it is generally possible to create generic objects, guis, etc and then configure them on the fly as needed.  There are a number of techniques that can be used depending upon what you are trying to accomplish.

A generic gui for example could contain a collection of buttons, lists, labels, etc which are positioned off screen when not used.  When a "new" gui is created then the desired complement of controls would be positioned on screen and modified with appropriate text and graphics.  The destructor function would then move the controls back off screen.

Also note that objects, guis, characters, etc can generally be accessed via a built-in pointer array.  For example a character named Ego can be accessed using the pointers character[cEgo.ID] or cEgo.  So if there were a number of generic elements it would be possible to search through a list to find a n unused one.

Hope this helps.

fireapache

Thanks, RickJ, very good reply!  ;D

SMF spam blocked by CleanTalk