I was wondering if some one could tell me how to make a code to save and load games using Ti-Basic (mainly on the Ti-84+), and maybe explain it to me.
Zerocode wrote:
I was wondering if some one could tell me how to make a code to save and load games using Ti-Basic (mainly on the Ti-84+), and maybe explain it to me.
Welcome to Cemetech, Zerocode! I'm glad that you took my suggestion about joining Cemetech that I made when you emailed me. Smile We're a pretty friendly bunch, so I hope you'll enjoy your stay. We know a pretty wide range of programming languages in case you code in anything besides TI-BASIC, there's a subforum for you to post about your projects, and SAX, the chat box at lower left of every Cemetech page, is populated more or less 24/7.

Regarding your question: most games that are designed to peacefully coexist with many other games and programs use a named list, eg LMINE, to store their saved data. Of course, each thing to be saved has to be a number of some kind, so this doesn't work (well) for things like strings. What kinds of things do you want to save? Do you want multiple simultaneous saves to be possible?
Or maybe you would like appvars more, Celtic 3 (and 2?) allow you to save stuff into appvars using "normal" ti basic. I say "normal" because they install hooks to use so that you can use regular ti basic code, but in different ways. If it is strings that you want to save, someone posted some code on another calculator site that saves a string as a list, and vice versa.

Welcome to Cemetech btw.
http://tifreakware.net/tutorials/83p/b/tifw/les3.htm

Here you can find a fairly detailed introduction to lists, how to create and use them. Anything more specific after you read this we will be more than happy to help explain to you and help you understand.
tifreak8x wrote:
http://tifreakware.net/tutorials/83p/b/tifw/les3.htm

Here you can find a fairly detailed introduction to lists, how to create and use them. Anything more specific after you read this we will be more than happy to help explain to you and help you understand.
Thanks for that, tifreak, your tutorials always seem to come in handy. Smile Please do check that out, Zerocode, and ping us with anything that doesn't make sense there.
No, not strings. I am not sure what is really called, but an example would be some thing along the lines of, your half way thought a game lvl and to you want to save before you go into a boss battle.

Also, how you do mult. saves?
To do multiple save files, you make multiple lists. Do read tifreak's tutorial still though, it helped me a lot when I was first learning lists Very Happy
Zerocode wrote:
No, not strings. I am not sure what is really called, but an example would be some thing along the lines of, your half way thought a game lvl and to you want to save before you go into a boss battle.

Also, how you do mult. saves?
Good, so you'd want to save things like health, location, armor, weapons, and all that, which can all be easily represented by numbers. There's two ways you can do saves. The first, less-desirable way, is to have a separate list for each save. LMINE1, LMINE2, LYOURS, or whatever. The second and better way to do it is to put all of the states into the same list. Say your data is 5 numbers. Then, you could have LMINE1 be 5 elements long for one save, or 25 elements long for 5 saves. To get out the 5 elements for save N, where N is 1, 2, 3, 4, or 5, you could just get:

LMINE1(5N-4
LMINE1(5N-3
LMINE1(5N-2
LMINE1(5N-1
LMINE1(5N
I skimmed over tifreaks8x tutorial and it seems to have what I want. If I need and more help I will get back to you.
hai thar, welcome to cemetech

Only guy you should look out for is nikky (you must guess who nikky is Razz)
he is never to be taken seriously Razz

anywho, I would have to agree with everyone, lists are your friends
Zerocode wrote:
I skimmed over tifreaks8x tutorial and it seems to have what I want. If I need and more help I will get back to you.
Excellent. Did _player's and my response to your question about multiple saves make sense? Be sure to post a topic about your project either now or when it starts congealing into a more finished form, your call. Smile
qazz42 wrote:
hai thar, welcome to cemetech

Only guy you should look out for is nikky (aka alyngflksjr)
he is never to be taken seriously Razz

anywho, I would have to agree with everyone, lists are your friends


Strings are still my favorite Very Happy But they are good for what they do, but for replacing lists, forget about it Razz
Here's how I go about it:

Let's say your important variables are A, B, and C. You want to keep their values so that you can resume playing the game whenever you want. All you do is store them to a list starting with 1:
Quote:
:{1,A,B,C}->LMINE


Now, let's say you want to load your game rather than start a new one. First, you check to see if the list exists and if it does, you load the info from the list to the variables:
Quote:
:4->dim(LMINE
:If LMINE(1) = 1
:Then
:LMINE(2)->A
:LMINE(3)->B
:LMINE(4)->C
:End

What this code does, essentially, is set the size of the list to 4 elements. If the list already exists, nothing happens. If it doesn't, it creates the list with 4 elements all set to 0. That's where that 1 comes in. If that first element is a 1, your list is still intact. If not, it isn't. Now you don't have to assume anything in your code Smile

NOTE HOWEVER, this method of storing from list to variables is pretty unoptimized. It's useful if you're better at remembering what variable is what based on letters (variable H is HP in some of my games) rather than on numbers (e.g. LMINE(7) is HP) and/or if you have few variables. But, if you have a lot of variables, it's best to just read from the lists directly.

If you want to do multiple saves, you just need some extra conditionals and a spare variable.
From a menu you can set a variable to some value corresponding to the save list you want to use. Same thing for loading. e.g.
Quote:
[menu code that sets S to 1 for the first save slot, or 2 for the second save slot]
:If S=1
:{1,A,B,C}->LMINE1
:If S=2
:{1,A,B,C}->LMINE2


If loading:
Quote:
[menu code that sets S to 1 for the first save slot, or 2 for the second save slot. You'd also want some code to determine what the menu outputs so you don't choose to load from Slot 2 if it doesn't exist.]
:If S=1
:Then
:LMINE1(2)->A
:LMINE1(3)->B
:LMINE1(4)->C
:End
:If S=2
:Then
:LMINE2(2)->A
:LMINE2(3)->B
:LMINE2(4)->C
:End



Of course, since I type slowly, this post will probably go to waste Razz

[Edited this post in accordance to a mistake pointed out by Player]
Thanks for the help, and it did make sense. I am really surpirised on how quick I got replys.
Zerocode wrote:
Thanks for the help, and it did make sense. I am really surpirised on how quick I got replys.
We aim to be as helpful as possible. Smile And Keith, very nice code there!
[Adding on to my last post]

If you're reading from lists directly, I don't know. My method of lists-only uses 1+N lists (where N = the number of save slots you want)

When you start the game, you load your important variables into a temporary list (say L1). Then, when you want to save, you just use pick one of the save slots (using aforementioned code or something similar) and just store the temp list to the save slot list.

When loading, you check to see which save slots exist, pick from one, and store it back to the temp list.


And thanks Kerm! Smile
Nice Keith, the only thing I noticed while reading it was that in your last code block that those should be if-then-end blocks. Zerocode, we try Very Happy
@_Player1537 fixed Smile


I feel weird giving advice on saving/loading in games. Lately, I've been working on games that don't implement any save features at all (although future games might). Past games haven't had much in terms of save features either because I haven't even gotten past some of the basics of their engines.

Basically, I'm giving advice without any practical tested experience to back it up Very Happy
_player1537 wrote:
Nice Keith, the only thing I noticed while reading it was that in your last code block that those should be if-then-end blocks. Zerocode, we try Very Happy
Good catch, _player! Those should indeed be if/then/end blocks.
How would you make a variable restore the variable as a biger number then use another variable. For intense in this quote how would you make A bigger with out using a different variable
Quote:
:4->dim(LMINE
:If LMINE(1) = 1
:Then
:LMINE(2)->A
:LMINE(3)->B
:LMINE(4)->C
:End
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement