Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / using ref inside a tier 1 user defined type

Author
Message
Prime
1
Years of Service
User Offline
Joined: 15th Jun 2022
Location:
Posted: 18th Sep 2022 18:12
The following module demonstrates a method of creating and using a ref-like variable within a user defined type while programming in Tier 1.

https://github.com/charlesgriffiths/agk-modules/tree/main/other/ref

Global variables are always an alternative, but crowd the namespace and their scope makes a large program difficult to analyze. Using a tRef adds minimal delay to variable access (typically under a microsecond) and the type will indicate whether data has been read or written more recently by use of the dirty flag. Using a ref within your own type allows you to write more generic code and not (for example) resort to copying a routine just to change the name of one global variable.


Ref_Init() create
Ref_Delete() delete
Ref_DeleteAll() delete all instances of tRef

Ref_IsDirty( tRef )
Ref_SetDirty( tRef )

get and set data via the type
Ref_GetInt( tRef )
Ref_SetInt( tRef, integer )
Ref_GetFloat( tRef )
Ref_SetFloat( tRef, integer )
Ref_GetString( tRef )
Ref_SetString( tRef, integer )

Ref_ToString( tRef ) puts the data in a tRef into a string

tRefa is like tRef but stores arrays instead of single values.


Comments welcome.

Login to post a reply

Server time is: 2024-04-20 03:35:35
Your offset time is: 2024-04-20 03:35:35