Example

PERSISTANCE

6

was8bit 2020-01-23 04:49 (Edited)

A mini game that demonstrates an "easy" method of using PERSIST memory that stores game state as well as game data...

TO PLAY MINI GAME...
===================
Arrow keys to move
+A button to remove plain stone or get pickups

Can only remove plain (non checkered) stone IF you have enough star power (shown top line near right side)

(Game note: BG 1 is the game board and is scrolled, BG 0 is data only and is not scrolled.... player is a sprite, scroll position is shown top-left corner)

PERSIST MEMORY SAVE METHOD USED....
====================================
BOTH BG 0 and BG 1 will get fully saved, all 32x32 cells

(Note: sprites are not auto-saved)

1) use BG 1 to store a game map 32x32 cells ...
-- any changes made to BG 1 will be saved (ie, removing or adding things)

2) use BG 0 to store game data
-- updated data will be saved
Examples of possible data....
-- player position
-- item totals
.... you can save game data beyond the visible 20x16 as the whole background is 32x32... use this trick to store game data that player doesnt need to see

The P image in the top right corner indicates that PERSIST MEMORY is being used...

The subs NEEDSAVE DOSAVE control how often PERSIST MEMORY is updated

The sub GETNUM pulls data that has been printed onto BG 0 and helps convert it back into game data memory


ANY QUESTIONS, PLEASE POST THEM HERE.... THANKS :)

Persistance.nx | Open in app
2020-01-23 04:49

Roger Davis 2020-01-23 09:14

Hi there was8bit, this MiniGame is great fun, and plays really well! But I do have some questions regarding the PERSIST MEMORY SAVE METHOD. Like how do you put the game data INTO BG 0 in the first place? 🤔 What's the method for doing that? Do you PRINT it in there or what? Secondly, . .would it be possible for you to show us what such a screen might look like? 🤔 - even if you have to "mock" a screenshot up? Thank you for sharing such a valuable trick with us! I understand the basis of it, it's just that I require a little more clarification. Thank you. 😃👍


Timo 2020-01-23 09:44

Storing an actual map this way makes sense, but I don't see why storing variables in a BG is better than just using PEEK and POKE.


was8bit 2020-01-23 11:00

@Roger, i use NUMBER,X,Y,variablename,numbershowndigits to show variables the screen..

See where is shows XY 216,176 ?

This puts the numbers on the screen during gameplay

BG 0
PAL 5
NUMBER 3,0,XSCROLL,3
NUMBER 7,0,YSCROLL,3

And this loads them back into the variables and resets the scroll when the game is rerun...

XSCROLL=0
YSCROLL=0
CALL GETNUM(3,0,3,XSCROLL)
CALL GETNUM(7,0,3,YSCROLL)
SCROLL 1,XSCROLL,YSCROLL


was8bit 2020-01-23 11:14

@Timo,

I agree that PEEK POKE works well for any variable whose value is strictly within the range of 0-255... however, number outside that range, and text names, get trickier and I get easilu confused at that point...

My approach is consistent and straight forword....

PERSIST approach for original lowres was simple and intuitive ... its going to be tricky for NX for newbies no matter what...

With accompanying SUBS, my approach isn't TOO much different then PEEK POKE... rather than trying to wrangle hex numbers into decimal numbers, all you have to do is reuse the same numbers you use to display the data using NUMBER, use these same numbers with my SUBS to reload... it is so much easier for me to align the data as far as using, storing, and retrieving them without getting all comfused..

I am sure others may prefer direct PEEK POKE, but for me if i have tired brains (as i often do) hex 10 and decimal 10 are 2 different numbers, and i would get confused and spend days trying to figure why my game isnt working right when all along i forgot to adjust for that difference...

my brains works best in decimal mode... hexs is a little confusing and,binary all the more confusing to my tired brains.... only when i have fresh rested brains can i figure them out...


was8bit 2020-01-23 11:20

For all....

Showing data on screen...

NUMBER X,Y,variablename,numofdigits

Loading data back into variable...

Variablename=0
CALL GETNUM(X,Y,numofdigits,variablename)


was8bit 2020-01-23 11:22

Would putting them in the same order be better...??

...l i think i will make a simpler example, and redo the order.....


Timo 2020-01-23 12:13

There is PEEKW, POKEW, PEEKL, POKEL for larger numbers. Just strings and floating point numbers are missing.


was8bit 2020-01-23 12:44

Memory addresses will totally confuse newbies...

So, try explaining how to store a 10 digit sized variable, and array of x,y positions,,etc. and get all of the memory addresses not confused or overlaped etc... i would struggle and for newbies this is not possible....

I know that PEEK POKE uses 1 memory block, PEEKW POKEW uses 2 memory blocks, and PEEKL POKEL uses 4 memory blocks..

So the math for time, score, and positions are...

$E000 for time
$E000+4 for score
And positions of 10 things...
For I=1 to 10
X(I)... $E000+8+I*2
Y(I)... $E000+8+I*2+1
Next I
...

.. now say i reedit my code and rearrange the variables... i have to recalculate ALL of my memory points... I'm sorry, but it is not worth all that trouble... it isnt fun any more, and i am not going to go thru all of that..

On the other hand, with my method, i can SEE my data, and SEE where it is as, and as my brain works visually, i can SEE where my data is stored and where to retrieve it... much simpler for me.....


Roger Davis 2020-01-23 13:52

Thank you was8bit! That's very helpful! I understand things a lot better now regarding this. Thank you also to Timo for his advice on this matter! : )


Lilsmitty420 2020-01-24 20:41

Hola


Roger Davis 2020-01-24 21:02

Hola!


was8bit 2020-01-25 06:37

Hey, lilsmitty.. glad you finally made it :D

... now, make some games ;)


was8bit 2020-01-31 06:18

@ Lilsmitty420

Here is what i promised.... it doesnt have help comments as i am abit tired... but do:
1) Open in app
2) touch up right corner and select Save to My Programs
3) then find it in your list of your games and open it
4) then while you can see the code, look for and tap the icon that is a square with an up arrow
5) then choose Share with Community
6) select Publish as New Program
7) fill the form (category WIP, title Gold Digger,text "wip")
8) tap the SUBMIT button

Congratulations, you have posted a game :)

Post questions there and i can post help there :)

Gold Digger.nx | Open in app
2020-01-31 06:19

Log in to reply.