Persistence saving/loading not working in TGE 1.5.2
by Dennis Lamers · in Torque Game Engine · 03/19/2016 (3:37 pm) · 4 replies
Hey all,
Another different problem I have with saving or loading persistence files in game. Whenever I use this script in TGE 1.1 the saving/loading persistence files works. Anyone who can help me out with this? Everything I build right now with friends is a waste of time. Hopefully someone is out there to solve the problem.
Another different problem I have with saving or loading persistence files in game. Whenever I use this script in TGE 1.1 the saving/loading persistence files works. Anyone who can help me out with this? Everything I build right now with friends is a waste of time. Hopefully someone is out there to solve the problem.
// Created by Rick
// rick@gibbed.us
// http://rick.gibbed.us/
// Version: 1.4
// Mission-oriented block persistence for Blockland.
// Copyright (c) 2005 gibbed.us
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the
// use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not claim
// that you wrote the original software. If you use this software in a product,
// an acknowledgment in the product documentation would be appreciated but is
// not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//function saveSchedule()
//{
// cancel(%testy);
// echo("automatic save");
// savePersistence();
// %testy = schedule(1000 * 60 * 1, 0, "saveSchedule");
//}
function clearMission()
{
%count = MissionCleanup.getCount();
messageAll("MsgPersistence", "c2The Administrator has cleared all the blocks ");
for (%i = 0; %i < %count; %i++)
{
%block = MissionCleanup.getObject(%i);
if (getSubStr(%block.dataBlock, 0, 11) $= "staticBrick" || getSubStr(%block.dataBlock, 0, 11) $= "staticPlate" || getSubStr(%block.dataBlock, 0, 11) $= "staticSlope" || getSubStr(%block.dataBlock, 0, 14) $="staticcylinder" || getSubStr(%block.dataBlock, 0, 11) $="staticfence")
{
MissionCleanup.getObject(%i).Explode();
}
}
}
function loadPersistence($UniquePersistName)
{
messageAll("MsgPersistence", "c4Blocks are being loaded from c3" @ $UniquePersistName @ ".persistence. c4please be patient...");
%filename = $Server::MissionFile @ "_" @ $UniquePersistName @ ".persistence";
echo("Loading persistence file " @ %filename);
exec(%filename);
//%testy = schedule(1000 * 60 * 1, 0, "saveSchedule");
//saveSchedule();
}
function savePersistence($UniquePersistName)
{
messageAll("MsgPersistence", "c4Blocks are being saved to c3" @ $UniquePersistName @ ".persistencec4. please be patient...");
saveBlocks("./" @ $Server::MissionFile @ "_" @ $UniquePersistName @ ".persistence");
saveLists();
}
function saveBlocks(%filename)
{
// Let's add some brick "persistence".
%file = new FileObject();
%file.openForWrite(%filename);
// Generate script which searches for
// baseplates in the level and assigns them to variables.
// It also sets the baseplate color. :)
%file.writeLine("// Search for baseplates");
%file.writeLine("for (%i = 0; %i < MissionGroup.getCount(); %i++)");
%file.writeLine("{");
%file.writeLine("t%obj = MissionGroup.getObject(%i);");
%file.writeLine("tif (%obj.dataBlock $= "gray32")");
%file.writeLine("t{");
%count = MissionGroup.getCount();
%first = true;
for (%i = 0; %i < %count; %i++)
{
%obj = MissionGroup.getObject(%i);
if (%obj.dataBlock $= "gray32")
{
if (%first)
{
%file.writeLine("ttif (%obj.position $= "" @ %obj.position @ "")");
%file.writeLine("tt{");
%first = false;
}
else
{
%file.writeLine("ttelse if (%obj.position $= "" @ %obj.position @ "")");
%file.writeLine("tt{");
}
%file.writeLine("ttt%obj.setSkinName("" @ %obj.getSkinName() @ "");");
%file.writeLine("ttt%block" @ %obj @ " = %obj;");
%file.writeLine("tt}");
}
}
%file.writeLine("t}");
%file.writeLine("}");
%file.writeLine("");
// Generate script to create bricks and plates
%count = MissionCleanup.getCount();
%file.writeLine("// Block creation");
for (%i = 0; %i < %count; %i++)
{
%block = MissionCleanup.getObject(%i);
if (getSubStr(%block.dataBlock, 0, 11) $= "staticBrick" || getSubStr(%block.dataBlock, 0, 11) $= "staticPlate" || getSubStr(%block.dataBlock, 0, 11) $= "staticSlope" || getSubStr(%block.dataBlock, 0, 11) $= "staticFence" || getSubStr(%block.dataBlock, 0, 14) $="staticcylinder")
{
%file.writeLine("%block" @ %block @ " = new StaticShape()");
%file.writeLine("{");
%file.writeLine("tposition = "" @ %block.position @ "";");
%file.writeLine("trotation = "" @ %block.rotation @ "";");
%file.writeLine("tscale = "" @ %block.scale @ "";");
%file.writeLine("tdataBlock = "" @ %block.dataBlock @ "";");
%file.writeLine("towner = "" @ %block.owner @ "";");
%file.writeLine("};");
%file.writeLine("MissionCleanup.add(%block" @ %block @ ");");
%file.writeLine("%block" @ %block @ ".setSkinName("" @ %block.getSkinName() @ "");");
%file.writeLine("");
}
}
%file.writeLine("// Block links");
for (%i = 0; %i < %count; %i++)
{
%block = MissionCleanup.getObject(%i);
if (getSubStr(%block.dataBlock, 0, 11) $= "staticBrick" || getSubStr(%block.dataBlock, 0, 11) $= "staticPlate" || getSubStr(%block.dataBlock, 0, 11) $= "staticSlope" || getSubStr(%block.dataBlock, 0, 11) $= "staticFence" || getSubStr(%block.dataBlock, 0, 14) $="staticcylinder")
{
%k = 0;
for (%j = 0; %j < %block.upSize; %j++)
{
if (MissionCleanup.isMember(%block.up[%j]) || %block.up[%j].dataBlock $= "gray32")
{
%file.writeLine("%block" @ %block @ ".up[" @ %k @ "] = %block" @ %block.up[%j] @ ";");
%k++;
}
}
%file.writeLine("%block" @ %block @ ".upSize = "" @ %k @ "";");
%k = 0;
for (%j = 0; %j < %block.downSize; %j++)
{
if (MissionCleanup.isMember(%block.down[%j]) || %block.down[%j].dataBlock $= "gray32")
{
%file.writeLine("%block" @ %block @ ".down[" @ %k @ "] = %block" @ %block.down[%j] @ ";");
%k++;
}
}
%file.writeLine("%block" @ %block @ ".downSize = "" @ %k @ "";");
}
}
%file.writeLine("// Baseplate links");
%count = MissionGroup.getCount();
for (%i = 0; %i < %count; %i++)
{
%obj = MissionGroup.getObject(%i);
if (%obj.dataBlock $= "gray32")
{
%file.writeLine("%i = %block" @ %obj @ ".upSize;");
for (%j = 0; %j < %obj.upSize; %j++)
{
if (isObject(%obj.up[%j]) && MissionCleanup.isMember(%obj.up[%j]))
{
%file.writeLine("%block" @ %obj @".up[$i++] = %block" @ %obj.up[%j] @ ";");
}
}
%file.writeLine("%block" @ %obj @ ".upSize = %i;");
%file.writeLine("%i = %block" @ %obj @ ".downSize;");
for (%j = 0; %j < %obj.downSize; %j++)
{
if (isObject(%obj.down[%j]) && MissionCleanup.isMember(%obj.down[%j]))
{
%file.writeLine("%block" @ %obj @ ".down[$i++] = %block" @ %obj.down[%j] @ ";");
}
}
%file.writeLine("%block" @ %obj @ ".downSize = %i;");
}
}
// JBM: Save # of blocks
%file.writeLine("$numBlocks = " @ $numBlocks @ ";");
%file.close();
// A new .persistence file will not be loadable until Blockland restarts,
// so we force Blockland to regenerate it's filename cache.
setModPaths(getModPaths());
echo("Save finished.");
}About the author
Creator of Peekarica and Blockland Classic Mod.
#2
Yesterday I found a v1.3 .exe file of tutorial.base on another Torque tutorial website. Saving and loading worked there. There problem is; it wont output the file (saving it) in v1.5.2. I think that there is a little tiny code in the script that has to be changed to make it work.
03/20/2016 (2:34 am)
Thanks for your fast reply Nathan. However this is the freeware Blockland from late 2004. It was the prototype before Blockland Retail was released in 2007. The old Blockland was also famous for it's large modification Return To Blockland. Blockland 0002 didn't had any engine changes it only had ski'ing, jetpack and swimming coded.Yesterday I found a v1.3 .exe file of tutorial.base on another Torque tutorial website. Saving and loading worked there. There problem is; it wont output the file (saving it) in v1.5.2. I think that there is a little tiny code in the script that has to be changed to make it work.
#3
Your code above has this for saving:
===================================
function saveBlocks(%filename)
{
// Let's add some brick "persistence".
%file = new FileObject();
%file.openForWrite(%filename);
=======================================
This is what I typically use in Torque, It will also provide a few more checks along the way.
===================================================
%file = new FileStreamObject(); // This is a different method
%fileName = expandFileName( %filename );
echo( "Attempt to open " , %fileName);
%file.open(%fileSelector,"write");
echo( "Open for Read for naming and creating character" , (%fileIsOpen ? "succeeded" : "failed" ) );
===============================================
03/20/2016 (5:13 pm)
See if this works. I use this process to write a file in Torque.Your code above has this for saving:
===================================
function saveBlocks(%filename)
{
// Let's add some brick "persistence".
%file = new FileObject();
%file.openForWrite(%filename);
=======================================
This is what I typically use in Torque, It will also provide a few more checks along the way.
===================================================
%file = new FileStreamObject(); // This is a different method
%fileName = expandFileName( %filename );
echo( "Attempt to open " , %fileName);
%file.open(%fileSelector,"write");
echo( "Open for Read for naming and creating character" , (%fileIsOpen ? "succeeded" : "failed" ) );
===============================================
#4
========= Change these 5 lines ===========
function saveBlocks(%filename)
{
// Let's add some brick "persistence".
%file = new FileObject();
%file.openForWrite(%filename);
=========================================
========== To this ==================
function saveBlocks(%filename)
{
echo("function saveBlocks(%filename) This is the filename " @ %filename);
// use this echo to make sure that %filename is feeding over a path to file
// Make sure the path to the file exists in the game directory
%file = new FileStreamObject();
%fileSelector = expandFileName( %filename );
%file.open(%fileSelector,"write");
// ====================================
03/21/2016 (2:07 pm)
Try this, I think I screwed up some of the variable names. Sorry about that.========= Change these 5 lines ===========
function saveBlocks(%filename)
{
// Let's add some brick "persistence".
%file = new FileObject();
%file.openForWrite(%filename);
=========================================
========== To this ==================
function saveBlocks(%filename)
{
echo("function saveBlocks(%filename) This is the filename " @ %filename);
// use this echo to make sure that %filename is feeding over a path to file
// Make sure the path to the file exists in the game directory
%file = new FileStreamObject();
%fileSelector = expandFileName( %filename );
%file.open(%fileSelector,"write");
// ====================================
Torque Owner Nathan Martin
TRON 2001 Network