TGC Codebase Backup



Saving A Matrix by MikeS

12th Mar 2004 21:48
Summary

Teaches how to save a matrix for later use.



Description

Teaches how to save a matrix for later use. Very vaulable and basic barebones of making a matrix editor.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    ` This tutorial was created by Yellow -Mike- 3-12-04
` Although not necessary, it would be nice to be credited and
` notified at yellow1dbp@hotmail.com if this was used in a game
` Thanks, and I hope the tutorial helps.

`Saving the matrix

sync on : sync rate 60 `Sets up the refresh rate
set display mode 1024,768,32 `sets up the display mode

make matrix 1,1000,1000,50,50 `Make the matrix for our example

main: `where we're sent after saving
do

`Randomizes our matrix so we can test it out saving
if returnkey()=1
 randomize matrix 1,15
 update matrix 1
endif

if spacekey()=1 then goto Save `save the matrix
if controlkey()=1 then goto load `load the matrix

control camera using arrowkeys 0,1,1 `controls the camera

sync
loop



```````````````````````````````````````````````````````````````````````
```````````Save`````````````
```````````````````````````````````````````````````````````````````````
Save:
input "INSERT FILEPATH HERE FOR WHERE ARRAY GETS SAVED",name$
set dir ""`+name$

`Creates the array the 50x50 will need to be changed to whatever
`dimensions you have for your array throughout this snippet.
dim matrixheight(1,50,50)

`These lines get the matrix height points. And are later saved
`in the dim array.
for x = 0 to 50
for z = 0 to 50
 matrixheight(1,x,z) = get matrix height(1,x,z)
next x
next z
 save array name$,matrixheight(1,x,z) `Saves the array


goto main `sends us to our main
```````````````````````````````````````````````````````````````````````
```````````Load`````````````
```````````````````````````````````````````````````````````````````````

load:
input "",name$
set dir "INSERT SAME FILEPATH HERE AS THE ABOVE"
dim matrixheight(1,50,50)          `Creates the array

load array name$,matrixheight(1,x,z) `Loads the array

`This gets the matrix height data from the dim array if it exists.
 for x = 0 to 50
 for z = 0 to 50
set matrix height 1,x,z,matrixheight(1,x,z)
 next x
 next z

 update matrix 1

goto main `sends us to our main

remstart
Ideally, you can just stick this code to the bottom of any matrix program
and change the dimensions to your need. You'll now have a way to save
matrices, and make an easy matrix creator.

Hope this helped
Copyright(c) CurvedBasic 2004

remend