Short fallout style text game (Merged from multiple topics)

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Wall_Axe
Manic Miner
Posts: 500
Joined: Mon Nov 13, 2017 11:13 pm

Short fallout style text game (Merged from multiple topics)

Post by Wall_Axe »

One interesting thing about fallout is playing as a stupid,lucky or charismatic character and seeing the differences in what happens.

I thought that this is simple enough for a zx spectrum basic game.
It could be:
A text adventure
have simple combat
Have choosable dialogue options that change depending on your stats.

To make it something that I won't abandon I was thinking of only having two situations in the game.
A situation is a quest basically.
It could be a locked door or a child in a well.

I wanted to crowdsource ideas.

To keep it a manageable project I was thinking of only three options:
Physically strong
Intelligent
Or.
Charismatic

Character
The two situations could be a base to explore and a group of ruffians to deal with outside the base.
Unless someone has better ideas.

The base would only consist of three or four rooms.
Wall_Axe
Manic Miner
Posts: 500
Joined: Mon Nov 13, 2017 11:13 pm

Boriel 2d arrays

Post by Wall_Axe »

I signed up for the boriel forum but when I log in the forum goes blank.
Does anyone know a good way of storing text descriptions of rooms in a text adventure?
I was using 2d arrays in basic ,but I got tired of line numbers and variables composed of only one letter.

But boriel is one dimensional arrays only
User avatar
WhatHoSnorkers
Manic Miner
Posts: 254
Joined: Tue Dec 10, 2019 3:22 pm

Re: Boriel 2d arrays

Post by WhatHoSnorkers »

Just a thought, could you just do one MASSIVE string and substring it? I've seen people do that in BASIC, like each 32 characters are one room?
I have a little YouTube channel of nonsense
https://www.youtube.com/c/JamesOGradyWhatHoSnorkers
User avatar
PeterJ
Site Admin
Posts: 6879
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Boriel 2d arrays

Post by PeterJ »

Good idea @WhatHoSnorkers,

I believe @TMD2003 uses a similar approach in Corona-Chan's Existential Christmas Crisis.
User avatar
Joefish
Rick Dangerous
Posts: 2059
Joined: Tue Nov 14, 2017 10:26 am

Re: Boriel 2d arrays

Post by Joefish »

Do you need to store them all in strings all at once? In BASIC, I'd be using DATA statements then RESTORE to the line of the one room I wanted.
Sinclair BASIC string arrays are a bit of a myth anyway. It's really a 2D character array; all the strings have to be the same length. If you could have an array of variable-length strings, it'd be a lot more useful. So really, storing them in fixed length chunks in a longer string is the same thing. You could use a separate numeric array to store the start and length of each slice of the string, so then it's only as long as it needs to be.

There is a get-around in ordinary BASIC where you an have a few strings, say A$, B$, C$, D$, E$ which will be of variable lengths, then access them by number with the expression VAL$("ABCDE"(n)+"$") where 'n' is 1..5. That will pick out the letter A,B,C,D or E indexed by 'n', add '$' on the end, then give you that string (if it exists). But I doubt that will compile in Boriel's BASIC.
User avatar
Seven.FFF
Manic Miner
Posts: 744
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Boriel 2d arrays

Post by Seven.FFF »

If you're struggling with that forum, Boriel's BASIC is also discussed in this discord, and Boriel himself is there too.

Boriel does have READ, DATA and RESTORE, so Joefish's first suggestion should work. RESTORing is done by labels or line numbers (line numbers are just numeric labels in Boriel anyway). I'm not sure if you can have calculated labels or calculated line numbers.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
TMD2003
Rick Dangerous
Posts: 2045
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Re: Boriel 2d arrays

Post by TMD2003 »

PeterJ wrote: Thu Aug 24, 2023 2:54 pm I believe @TMD2003 uses a similar approach in Corona-Chan's Existential Christmas Crisis.
I'd have to re-familiarise myself with what I did there in a fit of despair about the state of the world in late 2020.

Corona-chan would still be an excellent Chinese waifu if only the virulent malevolence could be forcibly removed from her, even after all this time. Give me a sword and I'll slash your bat wings off, bitch. Xixixixixixixixixixixi!
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
Wall_Axe
Manic Miner
Posts: 500
Joined: Mon Nov 13, 2017 11:13 pm

Re: Boriel 2d arrays

Post by Wall_Axe »

I suppose it boils down to either thinking of the game world as a 2d array like I'm doing....
or creating a 1d array of numbered rooms.

So with snorks idea it would be the 1d array as the strings would be within a 1d string .

The idea about read and restore is similar as it's linear (1 dimensional) as well.

So really what you are all saying is the same thing expressed in different ways:
Create a 1d array instead.
User avatar
Seven.FFF
Manic Miner
Posts: 744
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Boriel 2d arrays

Post by Seven.FFF »

If you always have the same number of items in the second dimension of your array, then

DIM array[5,3]
LET x = array[i, j]

For a two-dimensional array is really the same as

DIM array[15]
LET x = array[i+j*3]

For a one-dimensional array.

(This is some imaginary syntax I made up to illustrate the example, not Boriel or Sinclair BASIC, but hopefully you see what I mean.)
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
Wall_Axe
Manic Miner
Posts: 500
Joined: Mon Nov 13, 2017 11:13 pm

Re: Boriel 2d arrays

Post by Wall_Axe »

Ok that's nice n simple then thanks
Wall_Axe
Manic Miner
Posts: 500
Joined: Mon Nov 13, 2017 11:13 pm

Reading a 16 bit value at (IX+4)

Post by Wall_Axe »

It seems the z80 can read and write 8bit values from and to offsets very easily. But how would you read a 16 bit value from IX+4 for example?
User avatar
ParadigmShifter
Manic Miner
Posts: 671
Joined: Sat Sep 09, 2023 4:55 am

Re: Reading a 16 bit value at (IX+4)

Post by ParadigmShifter »

ld a, (ix+4)
ld l, a
ld a, (ix+5)
ld h, a

but it's pretty slow that.
User avatar
SkoolKid
Manic Miner
Posts: 407
Joined: Wed Nov 15, 2017 3:07 pm

Re: Reading a 16 bit value at (IX+4)

Post by SkoolKid »

The simplest way would be something like this:

Code: Select all

LD L,(IX+4)
LD H,(IX+5)
SkoolKit - disassemble a game today
Pyskool - a remake of Skool Daze and Back to Skool
Wall_Axe
Manic Miner
Posts: 500
Joined: Mon Nov 13, 2017 11:13 pm

Re: Reading a 16 bit value at (IX+4)

Post by Wall_Axe »

Thanks I'll give that a go
Wall_Axe
Manic Miner
Posts: 500
Joined: Mon Nov 13, 2017 11:13 pm

Re: Reading a 16 bit value at (IX+4)

Post by Wall_Axe »

actually im trying to put an address into IX and then I need to put that address +4 into HL

How would I do that? at the moment I'm simply loading it into DE and then doing addition on DE using the DJNZ loop.

I just wondered if its better or easier to use IX+ for that?
User avatar
ParadigmShifter
Manic Miner
Posts: 671
Joined: Sat Sep 09, 2023 4:55 am

Re: Reading a 16 bit value at (IX+4)

Post by ParadigmShifter »

SkoolKid wrote: Sat Sep 30, 2023 2:20 pm The simplest way would be something like this:

Code: Select all

LD L,(IX+4)
LD H,(IX+5)
Yup, that will also work.
I forgot you can use H or L at the same time as IX or IY.
User avatar
ParadigmShifter
Manic Miner
Posts: 671
Joined: Sat Sep 09, 2023 4:55 am

Re: Reading a 16 bit value at (IX+4)

Post by ParadigmShifter »

Wall_Axe wrote: Sat Sep 30, 2023 2:27 pm actually im trying to put an address into IX and then I need to put that address +4 into HL

How would I do that? at the moment I'm simply loading it into DE and then doing addition on DE using the DJNZ loop.

I just wondered if its better or easier to use IX+ for that?
ld de, 4
add ix, de

if you really then need it in HL you can

push ix
pop hl

but you have it in IX already

or you can do

push ix
pop hl
ld de, 4
add hl, de

if you want to preserve IX register
User avatar
ParadigmShifter
Manic Miner
Posts: 671
Joined: Sat Sep 09, 2023 4:55 am

Re: Reading a 16 bit value at (IX+4)

Post by ParadigmShifter »

Might be worth posting some code anyway, even if there is a comment in place of what you don't know how to do.

Looks like you're using IX way more than you should be to be honest. It's ok if it's pointing at a struct I suppose. Typically for stuff like that I index the start of the data with HL and just increment it from one field of the data to the next, you don't need random access to data MOST of the time, you can usually just access it sequentially.
User avatar
ketmar
Manic Miner
Posts: 713
Joined: Tue Jun 16, 2020 5:25 pm
Location: Ukraine

Re: Reading a 16 bit value at (IX+4)

Post by ketmar »

ParadigmShifter wrote: Sat Sep 30, 2023 2:54 pmTypically for stuff like that I index the start of the data with HL and just increment it from one field of the data to the next, you don't need random access to data MOST of the time, you can usually just access it sequentially.
…and then you suddenly decided to re-orgatize your data structures… after ~15th rewrite of the half of XTE i am now exclusively using IX-relative access. ;-)
User avatar
ParadigmShifter
Manic Miner
Posts: 671
Joined: Sat Sep 09, 2023 4:55 am

Re: Reading a 16 bit value at (IX+4)

Post by ParadigmShifter »

If you need to random access the data IX is fine (e.g. enemy data with lots of fields say).

Also fine if it is setup code not done every frame (like level initialisation etc.), menus etc.

If the OP is using IX just because they have run out of registers there is probably a better way to do things is all I was hinting at.
User avatar
ketmar
Manic Miner
Posts: 713
Joined: Tue Jun 16, 2020 5:25 pm
Location: Ukraine

Re: Reading a 16 bit value at (IX+4)

Post by ketmar »

sure, there is almost always a better way to do something. but i believe that for the beginner it is better first learn to write a working code, and only then learn to write a good working code. ;-) trying to learn optimising tricks in the same time as learning to simply write something that works usually creates a lot of confusion. and often leads to learning "magic tricks" instead of learning how to write programs.

at least for me, it works like this:
1. write the dumbest code possible.
2. make it work.
3. optimise the hell out of it (usually rewriting it several times, sometimes from the scratch).
4. then comes Einar and shows than my "optimised" code sux. ;-)

i don't mean to tell you that you're doing something wrong, btw, sorry. as we've basically answered the OP question, we're now mostly chit-chatting here, i believe. at least i need some smalltalk, because otherwise i start speaking exclusively in Z80 asm mnemonics soon. ;-)
User avatar
ParadigmShifter
Manic Miner
Posts: 671
Joined: Sat Sep 09, 2023 4:55 am

Re: Reading a 16 bit value at (IX+4)

Post by ParadigmShifter »

Learning how to cope with not very many registers is worth learning even as a beginner (like the OP seems to be) though I think.

Would be handier if we knew what the OP wants to do in the code they are writing of course.

It sounds like they either aren't using the stack enough or they're not reading data sequentially.

No offence taken of course, chit chat is good ;)
User avatar
ketmar
Manic Miner
Posts: 713
Joined: Tue Jun 16, 2020 5:25 pm
Location: Ukraine

Re: Reading a 16 bit value at (IX+4)

Post by ketmar »

ParadigmShifter wrote: Sat Sep 30, 2023 5:14 pm Would be handier if we knew what the OP wants to do in the code they are writing of course.
yeah, this is often the most important, yet most ommited part of a question. ;-)

2OP: don't be afraid to be wordy in your questions, please. it is always good to add some supplemental info. like, "i need to read 16-bit value at (IX+4). i am trying to write a routine for … here's my code (if there is any)."

this way we'll be able to help you better. there is nothing wrong in having non-optimal or even wrong code, and showing it in your question. we all were beginners once, nobody was born with the ability to write perfect programs. ;-) and we can suggest you other solitions, from which you could learn different ways to do things.

for example, for years i was sure that game authors are… not so brilliant-minded. looking in games, i've seen screen transfers with series of LDI commands, and thought "wut, nobody ever told them about that wonderful LDIR thing, or what?!" it took me a while to realise that LDIR is actually slower, and it was a Great Revelation. ;-) before that, i was absolutely sure that smaller code is always faster.
highrise
Manic Miner
Posts: 305
Joined: Fri Mar 20, 2020 11:29 pm

Re: Reading a 16 bit value at (IX+4)

Post by highrise »

There are also some useful commands using ixl and ixh, which are the high and low values of IX. They are documented here along with everything else

https://clrhome.org/table/


For example you can copy IX into DE using:

ld d,ixh
ld e,ixl

which would be slightly faster that using the stack.

you can also swap DE and HL using ex de,hl - at only 4 t-states it's very handy indeed for this kind of thing.
User avatar
ParadigmShifter
Manic Miner
Posts: 671
Joined: Sat Sep 09, 2023 4:55 am

Re: Reading a 16 bit value at (IX+4)

Post by ParadigmShifter »

Yup

ex de, hl

is great because HL can do more stuff than DE (mainly maths and you can do ld R, (hl) where R is any register, which you can't do with DE). (You can ld a, (RR) where RR is any register pair though).

You can't do

ex de, ix

or

ex de, iy

though.
Post Reply