Jump to content


Photo

use variable as key in ini file


  • Please log in to reply
3 replies to this topic

#1 the_maze_master

the_maze_master

    GMC Member

  • New Member
  • 51 posts

Posted 23 April 2012 - 11:33 AM

i want to use a variable as a key in an ini file, i am using this so a can add a new line of text (string) into the ini file and add as many as i like and change the "Key" each time by adding +1 to it


ini_open('filename.ini')

varA=ini_read_real('section','numberon',0)
varA+=1
varB=get_string('text to add','')

ini_write_real('section','numberon',obj_controler.varA)
ini_write_string('section',obj_controler.varA,obj_controler.varB)
ini_close()

the problem i am having is that the ini_write_string will not let me use the "varA" as the key, it ends up blank in the ini file

Edited by the_maze_master, 23 April 2012 - 11:45 AM.

  • 0

#2 TerraFriedSheep

TerraFriedSheep

    GMC Member

  • GMC Member
  • 2819 posts
  • Version:GM:Studio

Posted 23 April 2012 - 11:36 AM

ini_write_string('section',obj_controler.varA,obj_controler.varB)

the problem i am having is that the ini_write_string will not let me use the "varA" as the key, it ends up blank in the ini file


Shouldn't this line actually read:

ini_write_string('section',string(obj_controler.varA),obj_controler.varB)
  • 0

#3 the_maze_master

the_maze_master

    GMC Member

  • New Member
  • 51 posts

Posted 23 April 2012 - 11:44 AM

WOW that was fast and great, thank you loads, this worked great, not used "string()" in code like that before, will be a lot of help knowing this so extra big thanks :)

Edited by the_maze_master, 23 April 2012 - 11:45 AM.

  • 0

#4 TerraFriedSheep

TerraFriedSheep

    GMC Member

  • GMC Member
  • 2819 posts
  • Version:GM:Studio

Posted 23 April 2012 - 12:01 PM

WOW that was fast and great, thank you loads, this worked great, not used "string()" in code like that before, will be a lot of help knowing this so extra big thanks :)


No problem :)

The string() function converts a real value into a string, and as that argument in ini_write needs to be a string, this function will allow you to write the real number you have as a string into the ini file.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users