Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

TIC-80

Fantasy computer for making, playing and sharing tiny games. · By Nesbox

Pmem

A topic by ATSxp created Jan 04, 2022 Views: 228 Replies: 4
Viewing posts 1 to 2

Hi, I'm creating a game where one of its mechanics allows you to open and unlock doors, I used the "pmem" function to save the game, but I noticed that it doesn't save boolean variables (variables I use for the door system ) I want to know, is there a way to use pmem function with boolean variables?

(+2)

You're right, pmem() saves 32 bit integers. (https://github.com/nesbox/TIC-80/wiki/pmem )

The obvious workaround is to use 0 and 1 (or non-zero) to represent false/true but of course your code will need to be adapted to take that into account.

You could define (uppercase!) 'constants' at the start of your program and use them throughout:

local FALSE, TRUE = 0, 1

if flag==TRUE then...

Or you could just modify your 'if' statements: if flag==true then... becomes if flag==1 then...

Alternatively, you could create a function to examine the value and return true/false if that's essential for some reason. eg

function bool(i)
 if i==0 return false else return true end
end

and use it in your 'if' statements... if bool(flag) then.... but this adds the overhead of a function call for every use.

The best solution really depends on how/how frequently the values are used. Hope that gives you some ideas , sorry if you know all this already and just wanted to a basic answer (which is 'No') :D

(+1)

Well you're right, I already knew that XD, I just didn't want to stop using boolean variables because sometimes I write a "NOT" for boolean variables in a statement, which doesn't work with numbers ;_;, but ok I'll go reshape my code thanks for answering me =)

(+2)
if not(a==1) then...

works :D

(+1)