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.

Newcomers DBPro Corner / Loading And Saving A Label

Author
Message
Super Guy
13
Years of Service
User Offline
Joined: 20th May 2011
Location: Canada
Posted: 26th Oct 2012 00:36
How can I make it so that you can save a label and then load it again later? As in, it saves at a label in the code, and if you press load you can return to that label? Does that make sense?

I not only program but review video games too.

Get the latest video game reviews at http://v-g-r.blogspot.com/! Please follow.
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 26th Oct 2012 13:28 Edited at: 26th Oct 2012 13:33
You cannot save labels during runtime, they can only be created (and 'saved') during compile time.

When accessing ('loading') the labels are we talking without exiting the program? If the label has already been created (ie during compile time) then yes you can return to that label via goto (strongly discouraged however).

If the label has not already been created during compile time then I'm afraid the short answer is no. Although, it is most likely that what you want to accomplish can be done using subroutines and/or functions.

TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 26th Oct 2012 14:15
From what I understand you just want to somehow save the state of the game, and when the game starts again, start off from the same position in the game?

The simplest and easiest method for that is to create two routines for loading and saving your game.

The main concern in a game is saving all the data in your variables and arrays. Let's assume you have a player and an enemy with the following data:



You'll have to save all of that data to a file. This can be done like this:



You should save your game just before you end your program.

Loading your game again requires you to read all of that data back into the game, which you should do right when you start your program. The code for that is very similar:



This is just a very simple example, you'll have to adapt it to fit your own needs.

TheComet

- The codebase
Super Guy
13
Years of Service
User Offline
Joined: 20th May 2011
Location: Canada
Posted: 26th Oct 2012 16:29
Yes, I mean exited and then resuming where you were at. All I need to do is save the labels. So it can't be done?

I not only program but review video games too.

Get the latest video game reviews at http://v-g-r.blogspot.com/! Please follow.
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 26th Oct 2012 19:03
No, it can't be done because that's not how computers work. Read my post above again, it answers what you need to do instead.

TheComet

- The codebase
Super Guy
13
Years of Service
User Offline
Joined: 20th May 2011
Location: Canada
Posted: 26th Oct 2012 19:26
See, I am making a choose your own adventure game and I want it to save at certain times. I don't really think what you said above fits well with what I am doing.

I don't know what to do then.

I not only program but review video games too.

Get the latest video game reviews at http://v-g-r.blogspot.com/! Please follow.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 27th Oct 2012 03:52 Edited at: 27th Oct 2012 04:15
you can't use a variable to refer to a coded label directly in dbpro. you'll have to account for all possibilities/locations via code which uses a variable to refer to the various labels you might have.

Virtual Nomad @ California, USA . DBPro V7.7
AMD Phenomâ„¢ X4 9750 Quad-Core @ 2.4 GHz . 8 GB PC2-6400 RAM
ATI Radeon HD 3650 @ 512 MB . Vista Home Premium 64 Bit
Super Guy
13
Years of Service
User Offline
Joined: 20th May 2011
Location: Canada
Posted: 27th Oct 2012 12:23
That's confusing.

I not only program but review video games too.

Get the latest video game reviews at http://v-g-r.blogspot.com/! Please follow.
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 27th Oct 2012 13:21
Quote: "I don't really think what you said above fits well with what I am doing."


Well then have fun with finding a method that doesn't do what I said, may the force be with you.

TheComet

- The codebase
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 27th Oct 2012 21:30 Edited at: 27th Oct 2012 21:37
Okay. Super Guy, you wanna make a choose your own adventure game. Well firstly, you'll need to understand the basics.

1. As TheComet said, you need to be able to save ALL relevant playerdata. Even if you could do what you are wanting to in DBP, think how carefully you would have to structure the code; the nightmare of GOTOs it would be. That segways me nicely into point two...

2. Labels can be powerful allies but they'll usually just make your code unreadable, impossible to debug and slower-performing unless you really are smarter than your compiler. This:

is faster than this:

But you might end up with this:

if you're not careful. So take Hodgey's advice and forget GOTO.... But I sidetracked

3. The important bit: Games such as these are driven by flags in a dynamic code structure. So all you'll be doing in the gameplay is changing the numeric flags in accordance with player choices. Then you'll have handling functions to direct the story according to stuff like:
How many "like" points does the player have for Tifa?
What does choice(40) equal?
Was the "Deadly Badger Slayer" used on "Mount Scary-Doom"?


In short: Each "Choice Point" would be a program choice and have a value (easily only a binary one, although with events and items, etc, you may need more flags, ie: UNTOUCHED, GOT, USED). Flags would actually control what the player is able to see and what new choices are available to him/her.

Hope that cleared things up. Feel free to ask if you need further clarification.

RP Functions Library v1.0

Login to post a reply

Server time is: 2024-11-21 23:34:13
Your offset time is: 2024-11-21 23:34:13