Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / Code to save positions for all objects in your program to a text file

Author
Message
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 30th Dec 2004 03:43 Edited at: 30th Dec 2004 03:47
Nothing super special guys, but someone might be interested.. It's good for debugging



Basically loops to see if the object exists(i have it set to look for the first 50 objects), then gets their positions and saves it to a text file called object (whatever number the loop went through)

Enjoy.



WindowsXP Home(Service pack 2), Athlon XP 2400+(2.1Ghz), 1GIG Ram, Ati Radeon 9800Pro 128MB.
gbuilder
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: New Zealand
Posted: 30th Dec 2004 04:21
Great, could this be used for a 'save game' function. Could the text file be read to re-place objects where the were on saving?

gbuilder.

XP2000, 512mb Ram, 64mb GForce4 MX440 Graphics card, WindowsXP Professional.
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 30th Dec 2004 04:37
Wow Gbuilder, you thought ahead of me. I suppose it could indeed be used for exactly this

What you would need to do is after saving the positions previously, you would need to look to see how many objects it did save, then you would need to basically switch all the save operations to read operations, and then place the individual objects.

The only thing is, in your game you will have to create the object manually because the code doesnt make the object, it only places it.

So your mainline would look like

Create object cube 1,20
create object sphere 1,20,20,20 etc

And then you would call the load positions routine, and it would take the models currently loaded in and then place them back to where they were last time.



WindowsXP Home(Service pack 2), Athlon XP 2400+(2.1Ghz), 1GIG Ram, Ati Radeon 9800Pro 128MB.
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 30th Dec 2004 04:55 Edited at: 30th Dec 2004 04:57
I've modified the code a bit to do what you asked Gbuilder...

The saver for the positions of objects is here..


And the loader...


The error signifies that for example, if you run the saver program, it only saves two text files.. the loader program is trying to load 50.. The program still runs, but it'll give you an error saying it's gone past the amount it's supposed to have read.

[Edit] If anyone else finds this useful, be sure to say so

I also wouldnt mind if you told me if you used it in a finished game, my msn addy is found on the msn button. Have fun guys.



WindowsXP Home(Service pack 2), Athlon XP 2400+(2.1Ghz), 1GIG Ram, Ati Radeon 9800Pro 128MB.
gbuilder
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: New Zealand
Posted: 30th Dec 2004 05:45
Seems to work but for some reason the objects are not showing up for me.

gbuilder.

XP2000, 512mb Ram, 64mb GForce4 MX440 Graphics card, WindowsXP Professional.
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 30th Dec 2004 05:46
They're not supposed to.. i positioned them outside the screen view, but they are in their correct positions..

Load up the saver and change the positions of the objects so that they fit on screen, and run the program so the new variables kick into the text files for the objects.. Then run the loader again, you'll see that the objects are in the exact same place as they were when you ran the saver



WindowsXP Home(Service pack 2), Athlon XP 2400+(2.1Ghz), 1GIG Ram, Ati Radeon 9800Pro 128MB.
gbuilder
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: New Zealand
Posted: 30th Dec 2004 06:17
Yep, got it working. Nice

gbuilder.

XP2000, 512mb Ram, 64mb GForce4 MX440 Graphics card, WindowsXP Professional.
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 31st Dec 2004 12:57
Anyone else find this useful?



WindowsXP Home(Service pack 2), Athlon XP 2400+(2.1Ghz), 1GIG Ram, Ati Radeon 9800Pro 128MB.
mr dr
20
Years of Service
User Offline
Joined: 14th Jun 2004
Location: Minnesota USA
Posted: 31st Dec 2004 14:06
Would work wonderful for some sort of level editor.

On SSC Halo CTF as:
DaedalusX
20
Years of Service
User Offline
Joined: 10th Mar 2004
Location:
Posted: 1st Jan 2005 09:00
with a bit of editing i think u have my solved the problem that has been tinking in my mind since i started db 'how the hell do u save stuff' never been able to find anything usefull till now

Daedalus
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 1st Jan 2005 11:20
Cool, if you need any help.. feel free to post



WindowsXP Home(Service pack 2), Athlon XP 2400+(2.1Ghz), 1GIG Ram, Ati Radeon 9800Pro 128MB.
Blue Icarian Wings
20
Years of Service
User Offline
Joined: 21st Jun 2004
Location: About hereish
Posted: 7th Jan 2005 01:40
I wanted to double check if the val function would correctly convert a string number to a float number, from the comments here I gather the val command should work as I want

(using this in my level editor, advanced terrain and newton physics and waypoints (what I need Val for))

had a look in the codebase but there wasn't anything for expictly loading strings and converting them back to float, suggest you codebase this!
Neofish
20
Years of Service
User Offline
Joined: 7th Apr 2004
Location: A swimming pool of coke
Posted: 7th Jan 2005 05:26
I have a very nifty bit of code that uses memblocks to save arrays with UDTs to file and load them again, just make a routine to make the objects and it works fine

Blue Icarian Wings
20
Years of Service
User Offline
Joined: 21st Jun 2004
Location: About hereish
Posted: 7th Jan 2005 06:51
Care to share? lol
Essence
22
Years of Service
User Offline
Joined: 12th Oct 2002
Location: The Netherlands
Posted: 7th Jan 2005 09:14
You should do it like this:



Open the file with the same way. You can write that code yourself.
Neofish
20
Years of Service
User Offline
Joined: 7th Apr 2004
Location: A swimming pool of coke
Posted: 8th Jan 2005 03:17
Quote: " Care to share? lol"

Yeah ok

The UDT Array that goes with these snippets (decypher it yourself ):


Loading:


Saving:


Your welcome

Blue Icarian Wings
20
Years of Service
User Offline
Joined: 21st Jun 2004
Location: About hereish
Posted: 8th Jan 2005 22:15
@EvaX

My code does that already (I got text file string load/save sorted)

@Neofish

Thanks you dude, I'll be sure to make use of them when I tweak the level editor
DaedalusX
20
Years of Service
User Offline
Joined: 10th Mar 2004
Location:
Posted: 9th Jan 2005 07:24
having problems getting it to load the y angle of an object

Daedalus

Login to post a reply

Server time is: 2024-11-23 17:00:10
Your offset time is: 2024-11-23 17:00:10