Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (VoroneTZ, monk12, Quad), 829 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
putstr, getstr (similar to putvar, getvar) #477718
07/24/19 18:36
07/24/19 18:36
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online OP
Serious User
AndrewAMD  Online OP
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
jcl,

Currently, Zorro has putvar and getvar, to get and set vars.

In the same vein, perhaps a similar pair of functions can be used to get and set strings. Maybe call them putstr and getstr.

Thanks,
Andrew

Re: putstr, getstr (similar to putvar, getvar) [Re: AndrewAMD] #477737
07/25/19 17:48
07/25/19 17:48
Joined: May 2018
Posts: 134
S
SBGuy Offline
Member
SBGuy  Offline
Member
S

Joined: May 2018
Posts: 134
I agree. putvar and getvar and poorly implemented, supposedly for speed. I can't even store a 8 digit int YYYYMMDD using putvar because the printf used to write it to text file has limited float resolution.

Now it goes into the Windows registry? - Oy vey! Who's bright idea that? All we need is more junk in the Windows registry.

Better to store as string and use a faster computer :-)

I had to write my own getstr and putstr. For what it's worth, here it is

Code

string mygetstr(string fName, string itemName)
{
	string content = file_content(fName);
	if (!content) return 0;
	
	string myitem = strtext(content,strf("%s,",itemName),"0");
	if (!myitem) return 0;
	
	return myitem;
	
}

int myputstr(string fName, string itemName, string newval)
{
	string content = file_content(fName);
	if (!content) return 0;

	if (strstr(content,strf("%s,",itemName)))	{
		string myitem = strtext(content,strf("%s,",itemName),"0");
		if (!myitem) return 0;
			
		string old2 = strf("%s,%s",itemName,myitem);
		string newval = strf("%s,%s",itemName,newval);
		
		content = strx(content,old2,newval);
		file_write(fName,content,0);
	}
	else			
		file_append(fName,strf("%s,%s\n",itemName,newval));
}

var mygetvar(string fName, string itemName){
	return (atof(mygetstr(fName, itemName)));
}

function myputvar(string fName, string itemName, var val) {
	myputstr(fName, itemName,strf("%.3f",val));
}


Re: putstr, getstr (similar to putvar, getvar) [Re: AndrewAMD] #478088
09/05/19 23:29
09/05/19 23:29
Joined: Jan 2019
Posts: 73
berlin
L
laz Offline
Junior Member
laz  Offline
Junior Member
L

Joined: Jan 2019
Posts: 73
berlin
Isn't it a problem, to use so many temporary strings?

Or to return 0 for return type string?

Re: putstr, getstr (similar to putvar, getvar) [Re: AndrewAMD] #478122
09/10/19 15:32
09/10/19 15:32
Joined: May 2018
Posts: 134
S
SBGuy Offline
Member
SBGuy  Offline
Member
S

Joined: May 2018
Posts: 134
Hi Iaz,

Thanks for the code review. I swore that a few Zorro versions again, I read that temp strings lose their content after something like 10 other temp string calls. But the latest manual in 2.18.1b says temp strings loose value immediately after another temp string call. Yikes! I better fix my code :-)

As for return 0 for string time, isn't that the same as a NULL string pointer?

Re: putstr, getstr (similar to putvar, getvar) [Re: AndrewAMD] #478172
09/17/19 13:29
09/17/19 13:29
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
I can at least confirm that temp strings are recycled after 10 calls, not immediately. 0 is the same as NULL.


Moderated by  Petra 

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