• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Loading values from a ini file problem [Solved]

S

stephen2017

Guest
Hi all,
Little help needed please. What I am trying to do is load values from a ini file called Users. If the user1,user2 etc has a value I want to create a blank button with that string added to it and if no value exits as it goes through the loop then break out of the loop and stop creating buttons. Basically part of a log on screen for multiple users.

But at the moment its just creating buttons and not stopping when it finds "".

This is my ini file values.

[Name]
User1="John"
User2=""
User3=""
User4=""
User5=""
User6=""
User7=""
User8=""

Here is my code.

var User;
var ypos=40;
ini_open("Users.ini");
for(i=1; i<=8; i++){
User = ini_read_string("Name",string_insert(string(i), "User", 5),"")
if (User != ""){
instance_create(20,ypos,obj_Blankbutton);
ypos = ypos +50;
}
else{
break;
}
}
ini_close();
 

jo-thijs

Member
It works just fine for me.
Are you sure you're looking at the correct ini file,
that there is no other code creating buttons or changing the ini file during execution
and that this code is executing when the issue gets produced?
 
S

stephen2017

Guest
Yes definitely the right Ini file, this is the only load code I have so far. For me it creates 6 instances of Blankbutton. Where it should only be creating one as User1 is the only one with a set value. Do I have tried not having "" on any of the other values but it does the same thing.

Should I have something different in the If statement?? if(User != "") to stop the for loop when it does not get a name?

Might just do a if User1 = John to begin with and make sure that parts working and work through it from there.
 
S

stephen2017

Guest
Ok I think I have found part of the problem. My ini_read_string is not working for some reason. ini_read_real works as I have pulled a value and can display that on the screen. But I cant read and display the user1 string value for some reason. I am not sure why it will read a real number but not a string. Is there a certain syntax you need in your Ini files for strings????
 
Hmm...you've marked this problem as solved, but you last comment says you still couldn't get string reads to work. If you are still having problems, could you try putting a show_debug_message after you read the string?

Code:
show_debug_message("User = " + string(User))
See if the string matches what you would expect it to be.

Also, is your system locale on your computer set to English?
 
Top