Gamestudio Links
Zorro Links
Newest Posts
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
LPDIRECT3DCUBETEXTUR
E9

by Ayumi. 04/12/24 11:00
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 04/11/24 14:56
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (firecrest, AndrewAMD), 387 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
11honza11, ccorrea, sakolin, rajesh7827, juergen_wue
19045 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,725
Chicago
AndrewAMD Online OP
Serious User
AndrewAMD  Online OP
Serious User

Joined: Feb 2017
Posts: 1,725
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,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
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