Gamestudio Links
Zorro Links
Newest Posts
Issue with Starter Window
by txesmi. 10/23/19 09:22
Accessing All Historical Price Data
by JohnJits. 10/22/19 22:37
file_write var array ?
by laz. 10/22/19 16:00
SAV_STATS
by MatPed. 10/22/19 13:57
Instrument Price Zorro Chart
by jcl. 10/22/19 10:39
Calculating with price series
by AndrewAMD. 10/21/19 14:31
Error E355: Startup failure
by Dooley. 10/21/19 06:47
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
10 registered members (AndrewAMD, Uhrwerk, jenGs, MatPed, kvm, 20BN, Paulius, Dalla, 2 invisible), 635 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Bolle, VillageTalkies, line7, Shutch, Clifford_B
18311 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Document AssetInt and AssetFloat #474923
11/13/18 12:59
11/13/18 12:59
Joined: Feb 2017
Posts: 774
Chicago
AndrewAMD Online OP
User
AndrewAMD  Online OP
User

Joined: Feb 2017
Posts: 774
Chicago
jcl,

I think it would be useful for the manual to:
* Document AssetInt and AssetFloat
* Document how to avoid the problems I encountered, below.

- - - - -

I recently had the privilege to work on a custom indicator, where it seemed very practical to store some binary switches in an integer on a per-asset basis.

I dug into the headers, and I found these #define's:

Code:
#define AssetVar		(g->asset->Skill)
#define AssetStr		(char*)&(g->asset->Skill)
#define AssetInt		((int*)AssetVar)
#define AssetFloat		((float*)AssetVar)


... where Skill is a var array with 16 elements.

Cool, so I can use an AssetInt. Here was my naive implementation:

Code:
#define V0 AssetVar[0]
#define V1 AssetVar[1]
#define V2 AssetVar[2]
#define I3 AssetInt[3]


It took me an hour of debugging to figure out if and why my I3 int was giving me garbage values. Here was my fix:

Code:
#define V0 AssetVar[0]
#define V1 AssetVar[1]
#define V2 AssetVar[2]
#define I3 AssetInt[3*2]


As you can see, I had to double the array offset to position my integer correctly. In other words, I3 was originally at position 1.5 on the var array, so if I change the value of V1, it transforms I3 into a garbage value. The fix has I3 at position 3 of the var array, as desired.

As an added bonus, this means that the script writer can have:
* Up to 16 AssetVars, or
* Up to 16 AssetStrs (7 characters before null termination each), or
* Up to 32 AssetInts, or
* Up to 32 AssetFloats, or
* Any mix-and match of the above, with the appropriate pointer arithmetic.

Re: Document AssetInt and AssetFloat [Re: AndrewAMD] #474935
11/14/18 08:07
11/14/18 08:07
Joined: Jul 2000
Posts: 27,033
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,033
Frankfurt
We had not documented these macros because they were for internal use only. But we'll add them officially in the next update.

Re: Document AssetInt and AssetFloat [Re: jcl] #474946
11/14/18 14:23
11/14/18 14:23
Joined: Feb 2017
Posts: 774
Chicago
AndrewAMD Online OP
User
AndrewAMD  Online OP
User

Joined: Feb 2017
Posts: 774
Chicago
Thank you!


Moderated by  aztec, Inestical, Matt_Coles, Tobias 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1