Scripts / Deleting a temporary file on game end

Author
Message
Honkeyboy
3D Media Maker
9
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 3rd Mar 2021 17:24
I have a temp file which gets written into the main files directory of the standalone build, is there a way to delete this on the game ending? e.g all 3 lives lost otherwise the player keeps the score from when the game ends. Would this be in the gamedata.lua? and what would be needed to delete that file if it can be done, any ideas cheers
Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
XFX R5 2gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 3rd Mar 2021 17:32
make sure to close the file first (which you should be doing anyway) then use os.remove(path)
you could do this in your own script, check if g_PlayerLives < 1
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Honkeyboy
3D Media Maker
9
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 3rd Mar 2021 17:35 Edited at: 3rd Mar 2021 17:44
Yes m8 the file does close but my own scripts just save and its actually when the game ends i need it to delete not just on death if you get me.
Oh i see what your saying if lives <1 it should delete then end game yes? Should i write a separate script for this would you think?
like:


and run that on an always active entity?
Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
XFX R5 2gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 3rd Mar 2021 18:49
if lives is < 1 then that is game over so it's fine
should be ok in your own script yh, i'm 99% sure it'll run the final frame before the game goes back to the menu.
i haven't used the command personally (that i can remember) but it should be a string passed in to a function so more like
os.remove("asgood\asgoodCD\Files\temp.dat")
i'm not sure if you will need to pass the entire path or not tbh, should work similar to how you open the file so i guess it depends where the file is stored in relation to the game files
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Honkeyboy
3D Media Maker
9
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 3rd Mar 2021 19:35 Edited at: 3rd Mar 2021 20:59
ok will give it a try later after doing some backups cheers m8.
Edit : gives an error "invalid escape sequence"
hmm just found this:


A simple file open operation uses the following statement.

file = io.open (filename [, mode])
The various file modes are listed in the following table.

Sr.No. Mode & Description
1
"r"

Read-only mode and is the default mode where an existing file is opened.

2
"w"

Write enabled mode that overwrites the existing file or creates a new file.

3
"a"

Append mode that opens an existing file or creates a new file for appending.

4
"r+"

Read and write mode for an existing file.

5
"w+"

All existing data is removed if file exists or new file is created with read write permissions.

6
"a+"

Append mode with read mode enabled that opens an existing file or creates a new file.


so hopefully this will work lol using w+ instead of w

Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
XFX R5 2gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 3rd Mar 2021 21:13
Invalid escape sequence normally means you don't have enough '\'s
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 3rd Mar 2021 23:01 Edited at: 3rd Mar 2021 23:02
ah yes, as amen says, the error means you need to double the \ in the path
so
os.remove("asgood\\asgoodCD\\Files\\temp.dat")
because it treats a single \ as special call

but yes, good idea, w or w+ should be fine to overwrite the file by the looks of it
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Honkeyboy
3D Media Maker
9
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 3rd Mar 2021 23:09
oh right thanks but with the w+ you don't need to delete the file btl of it just wipes the data from it tbh using o.s remove i think means you have to change the path every time e.g the editor path is different to the standalone path. I've written the script will test it fully tomorrow, but thanks m8 you pointed me to the right path
Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
XFX R5 2gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 4th Mar 2021 02:06
Something like this clears the file for later use.

Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
Honkeyboy
3D Media Maker
9
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 5th Mar 2021 15:11
Cheers 3com

Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
XFX R5 2gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on

Login to post a reply

Server time is: 2024-12-22 02:28:38
Your offset time is: 2024-12-22 02:28:38