readinistring

Started by MEGAMIND, Jul 21, 2018, 06:18 PM

Previous topic - Next topic

MEGAMIND

*Bump* pls i do want solution to this

MEGAMIND

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;
  }
}


!

#17
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:


Discord: zeus#5155

MEGAMIND

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

ysc3839

@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);

MEGAMIND

I already did that bcz i didnt recieved an answer to my problem so i used ur thing the way u explained