Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (dr_panther, TedMar, AndrewAMD), 986 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Setting up strategy parameters from a .ini file #412423
11/27/12 09:54
11/27/12 09:54
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline OP

Chief Engineer
jcl  Offline OP

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Sometimes you want your strategy to read variables out of an external file. Use the file_content and sscanf functions for that:

Code:
// helper function - read a variable from a string
// with a format like "name = 12.34"
var readVar(string str,string name)
{
  float f = 0; // sscanf needs float
  string s = strstr(str,name);
  if(s) s = strstr(s,"=");
  if(s) sscanf(s+1,"%f",&f);
  return f;
}
 
function run()
{
  static var Parameter1 = 0, Parameter2 = 0;
  if(is(INITRUN)) { // read the parameters only in the first run
    string setup = file_content("Strategy\\mysetup.ini");
    if(setup) {
      Parameter1 = readVar(setup,"Parameter1");
      Parameter2 = readVar(setup,"Parameter2");
  }
}


mysetup.ini is a plain text file that contains the values of the variables, in a format like this:
Code:
Parameter1 = 123
Parameter2 = 456


Re: Setting up strategy parameters from a .ini file [Re: jcl] #412430
11/27/12 11:56
11/27/12 11:56
Joined: Feb 2012
Posts: 37
S
stevegee58 Offline
Newbie
stevegee58  Offline
Newbie
S

Joined: Feb 2012
Posts: 37
Is file_content new? I remember asking about reading files back when I was trying to write a data conversion script.

Re: Setting up strategy parameters from a .ini file [Re: stevegee58] #412434
11/27/12 12:56
11/27/12 12:56
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline OP

Chief Engineer
jcl  Offline OP

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
I believe it was implemented in version 0.99.


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