@name TestSaveAndLoad
@outputs String:array Finalpos:vector Pos:vector
@persist Tab:array Fpos:array E:entity

if(first()){
runOnChat(1)
runOnTick(1)
runOnFile(1)
E = entity():isWeldedTo()
}

if(chatClk(owner())){
String = owner():lastSaid():explode(" ")

if(String[1,string] == "!load"){
    
print("Loading")
fileLoad("test.txt")
}  

if(String[1,string] == "!save"){
print("Saved!")  

Pos = E:pos()
Str = ""
for(I=1,3){
Str = Str+Pos[I]+(I<3 ? "," : "")
}

print("Save : " + Str)

fileWrite("test.txt",Str)
}
}

if(fileClk()&fileLoaded()){

Array = fileRead():explode(",")
Vec = vec( Array[1,string]:toNumber(), Array[2,string]:toNumber(), Array[3,string]:toNumber() )

print("Loaded : " + Vec)

E:setPos(Vec)
}

setName(fileStatus():toString())
