Vice City: Multiplayer

VC:MP Discussion => Support => Topic started by: MEGAMIND on Jul 21, 2018, 06:18 PM

Title: readinistring
Post by: MEGAMIND on Jul 21, 2018, 06:18 PM
actually im new to ini and using this first time so how do i read ini

my WriteIniString is
WriteIniString("objects.ini","autosaved",i.tostring(), "CreateObject("+o.Model+","+o.World+",Vector"+o.Pos+","+o.Alpha+").RotateToEuler(Vector"+o.RotationEuler+",1);"); }

and my output to that is

[objects]
0                           = CreateObject(636,17,Vector(-1399.7, -650.131, 15.8679),255).RotateToEuler(Vector(3.0996, 3.0871, -1.26476),1);

how would i be able t read it

so far i have tried this but it wont work
if (ReadIniString( "objects.ini", "objects", i.tostring() )==null);
{
         print("objects reloaded");
    }
Title: Re: readinistring
Post by: NicusorN5 on Jul 21, 2018, 06:26 PM
To create the object:
for(local i =0 ; i < 3000; i++)
{
try{
compilestring("objects.ini","autosaved",i.tostring())
}
catch(e) { }
}
Title: Re: readinistring
Post by: MEGAMIND on Jul 21, 2018, 06:32 PM
Quote from: Athanatos on Jul 21, 2018, 06:26 PMTo create the object:
for(local i =0 ; i < 3000; i++)
{
try{
compilestring("objects.ini","autosaved",i.tostring())
}
catch(e) { }
}
y compile autosave i just want to read objects.ini so that wahtsoever object is present in objects.ini so when i join game the object should be present at its location + that for thing didnt worked too
Title: Re: readinistring
Post by: ! on Jul 21, 2018, 07:21 PM
Quote from: MEGAMIND on Jul 21, 2018, 06:32 PMy compile autosave i just want to read objects.ini so that wahtsoever object is present in objects.ini so when i join game the object should be present at its location + that for thing didnt worked too
Don't know about ini but after reading data from ini file you must have to compile it in order to create those objects at their locations.
Title: Re: readinistring
Post by: Stormeus on Jul 21, 2018, 07:37 PM
If you're going to the effort of writing Squirrel code in an INI file, why not just get rid of the INI part and use dofile?
Title: Re: readinistring
Post by: MEGAMIND on Jul 22, 2018, 06:23 AM
Quote from: Stormeus on Jul 21, 2018, 07:37 PMIf you're going to the effort of writing Squirrel code in an INI file, why not just get rid of the INI part and use dofile?
i had that idea befor but how du u right something in a dofile???
Title: Re: readinistring
Post by: MEGAMIND on Jul 22, 2018, 07:08 AM
Quote from: vitogta on Jul 22, 2018, 06:53 AMeval is evil
there was no reason to comment that
Title: Re: readinistring
Post by: DizzasTeR on Jul 22, 2018, 07:50 AM
Quote from: Stormeus on Jul 21, 2018, 07:37 PMIf you're going to the effort of writing Squirrel code in an INI file, why not just get rid of the INI part and use dofile?

He means since you are saving the data in ini as pure squirrel code, you can directly use dofile to load all the CreateObject statements from the ini file instead of reading them from ini as strings and then executing them/creating objects with them.

try
dofile("objects.ini")and it should load all the objects
Title: Re: readinistring
Post by: MEGAMIND on Jul 22, 2018, 08:01 AM
;) thanks doom, i didnt got Stormeus messeage in the firstplace....
Title: Re: readinistring
Post by: EK.IceFlake on Jul 22, 2018, 08:23 AM
Quote from: Doom_Kill3R on Jul 22, 2018, 07:50 AM
Quote from: Stormeus on Jul 21, 2018, 07:37 PMIf you're going to the effort of writing Squirrel code in an INI file, why not just get rid of the INI part and use dofile?

He means since you are saving the data in ini as pure squirrel code, you can directly use dofile to load all the CreateObject statements from the ini file instead of reading them from ini as strings and then executing them/creating objects with them.

try
dofile("objects.ini")and it should load all the objects

You can't dofile an ini, it'll cause errors. You should save them to a .nut file.
Title: Re: readinistring
Post by: MEGAMIND on Jul 22, 2018, 08:56 AM
Quote from: EK.IceFlake on Jul 22, 2018, 08:23 AM
Quote from: Doom_Kill3R on Jul 22, 2018, 07:50 AM
Quote from: Stormeus on Jul 21, 2018, 07:37 PMIf you're going to the effort of writing Squirrel code in an INI file, why not just get rid of the INI part and use dofile?

He means since you are saving the data in ini as pure squirrel code, you can directly use dofile to load all the CreateObject statements from the ini file instead of reading them from ini as strings and then executing them/creating objects with them.

try
dofile("objects.ini")and it should load all the objects

You can't dofile an ini, it'll cause errors. You should save them to a .nut file.
yeeep exactly got errors

(https://i.imgur.com/qkF8bj4.jpg)


and if i do this

if ( ReadIniString("objects.ini","objects",i.tostring()) == null )
    {
       print("nothing loads up");
    }

the console startsup normally but the objects doesnt load up saying

(https://i.imgur.com/gQSDwid.jpg)

whether it's onplayerjoin or onscriptload

Title: Re: readinistring
Post by: NicusorN5 on Jul 22, 2018, 09:43 AM
You need to use that loop part. That's there's isn't a variable named i.
Title: Re: readinistring
Post by: MEGAMIND on Jul 22, 2018, 09:58 AM
Quote from: Athanatos on Jul 22, 2018, 09:43 AMYou need to use that loop part. That's there's isn't a variable named i.
how ? u do know that im weak at ini
Title: Re: readinistring
Post by: =RK=MarineForce on Jul 22, 2018, 10:13 AM
print it? u want see whats in object.ini?

print("objects.ini"); xDD
Title: Re: readinistring
Post by: MEGAMIND on Jul 22, 2018, 10:50 AM
Quote from: =RK=MarineForce on Jul 22, 2018, 10:13 AMprint it? u want see whats in object.ini?

print("objects.ini"); xDD

At marine force pls stay out of this lol
Title: Re: readinistring
Post by: MEGAMIND on Jul 22, 2018, 05:51 PM
*Bump* pls i do want solution to this
Title: Re: readinistring
Post by: MEGAMIND on Jul 23, 2018, 08:04 AM
umm anyone i did this too but i dont see anyobject

NewTimer("LoadAllObjects",10000,1);

function LoadAllObjects()
{ local i = 0;
  while(true)
  {
    local str = ReadIniString( "objects.ini", "objects", i.tostring() );
    if(!str) break;
    else
    {
      local a = compilestring(str);
      a();

      i++;
    }
  }
  for(local a=0;a<GetObjectCount();a++)
  {
      FindObject(a).TrackingShots = true;
  }
}

Title: Re: readinistring
Post by: ! on Jul 23, 2018, 08:41 AM
Okay after learning some stuff about ini
http://wiki.vc-mp.org/wiki/Scripting/Squirrel/Functions/WriteIniString
http://wiki.vc-mp.org/wiki/Scripting/Squirrel/Functions/ReadIniString

Quote from: MEGAMIND on Jul 21, 2018, 06:18 PMmy WriteIniString is
WriteIniString("objects.ini","autosaved",i.tostring(), "CreateObject("+o.Model+","+o.World+",Vector"+o.Pos+","+o.Alpha+").RotateToEuler(Vector"+o.RotationEuler+",1);"); }
Quote from: MEGAMIND on Jul 23, 2018, 08:04 AMumm anyone i did this too but i dont see anyobject

NewTimer("LoadAllObjects",10000,1);

function LoadAllObjects()
{ local i = 0;
  while(true)
  {
    local str = ReadIniString( "objects.ini", "objects", i.tostring() );
    if(!str) break;
    else
    {
      local a = compilestring(str);
      a();

      i++;
    }
  }
  for(local a=0;a<GetObjectCount();a++)
  {
      FindObject(a).TrackingShots = true;
  }
}

Your mistake is the string section in both of these functions need to be same but you have used autosaved in WriteIniString while objects in ReadIniString
bool WriteIniString( string filename, string section, string var, string value )
string ReadIniString( string filename, string section, string var )

Since @Athanatos has already answered.
Use this and check console if it gives any message.
WriteIniString( "objects.ini", "autosaved", i.tostring(), "CreateObject( "+o.Model+", "+o.World+", Vector"+o.Pos+", "+o.Alpha+" ).RotateToEuler( Vector"+o.RotationEuler+", 1 );" );

function LoadAllObjects()
{
local i = 0;
while(true)
{
local str = ReadIniString( "objects.ini", "autosaved", i.tostring() );
if( !str ) break;
else
{
local eCompile = compilestring( str );
eCompile();
print( "Created Object: "+i );
i++;
}
}
for( local j = 0; j < GetObjectCount(); j++ )
{
FindObject(j).TrackingShots = true;
}
}
LoadAllObjects();
:edit:

Title: Re: readinistring
Post by: MEGAMIND on Jul 23, 2018, 08:45 AM
Quote from: ! on Jul 23, 2018, 08:41 AMOkay after learning some stuff about ini
http://wiki.vc-mp.org/wiki/Scripting/Squirrel/Functions/WriteIniString
http://wiki.vc-mp.org/wiki/Scripting/Squirrel/Functions/ReadIniString

Quote from: MEGAMIND on Jul 21, 2018, 06:18 PMmy WriteIniString is
WriteIniString("objects.ini","autosaved",i.tostring(), "CreateObject("+o.Model+","+o.World+",Vector"+o.Pos+","+o.Alpha+").RotateToEuler(Vector"+o.RotationEuler+",1);"); }
Quote from: MEGAMIND on Jul 23, 2018, 08:04 AMumm anyone i did this too but i dont see anyobject

NewTimer("LoadAllObjects",10000,1);

function LoadAllObjects()
{ local i = 0;
  while(true)
  {
    local str = ReadIniString( "objects.ini", "objects", i.tostring() );
    if(!str) break;
    else
    {
      local a = compilestring(str);
      a();

      i++;
    }
  }
  for(local a=0;a<GetObjectCount();a++)
  {
      FindObject(a).TrackingShots = true;
  }
}

Your mistake is the string section in both of these functions need to be same but you have used autosaved in WriteIniString while objects in ReadIniString
bool WriteIniString( string filename, string section, string var, string value )
string ReadIniString( string filename, string section, string var )

Since @Athanatos has already answered.
Use this and check console if it gives any message.
WriteIniString( "objects.ini", "autosaved", i.tostring(), "CreateObject( "+o.Model+", "+o.World+", Vector"+o.Pos+", "+o.Alpha+" ).RotateToEuler( Vector"+o.RotationEuler+", 1 );" );

function LoadAllObjects()
{
local i = 0;
while(true)
{
local str = ReadIniString( "objects.ini", "autosaved", i.tostring() );
if( !str ) break;
else
{
local eCompile = compilestring( str );
eCompile();
print( "Created Object: "+i );
i++;
}
}
for( local j = 0; j < GetObjectCount(); a++ )
{
FindObject(a).TrackingShots = true;
}
}
LoadAllObjects();

no errors and still not working
Title: Re: readinistring
Post by: ysc3839 on Jul 23, 2018, 06:32 PM
@Stormeus means: since you store an "executable code", you can simply store them in a nut and then use "dofile" to execute the code.
For example, if you use INI the file looks like:
[autosaved]
0=CreateObject(123, 0, Vector(1, 2, 3), 200).RotateToEuler(Vector(1, 2, 3), 1);
1=CreateObject(456, 0, Vector(1, 2, 3), 200).RotateToEuler(Vector(1, 2, 3), 1);

And if you use nut:
CreateObject(123, 0, Vector(1, 2, 3), 200).RotateToEuler(Vector(1, 2, 3), 1);
CreateObject(456, 0, Vector(1, 2, 3), 200).RotateToEuler(Vector(1, 2, 3), 1);
Title: Re: readinistring
Post by: MEGAMIND on Jul 24, 2018, 06:54 AM
I already did that bcz i didnt recieved an answer to my problem so i used ur thing the way u explained