#Need help with terminal game

67 messages · Page 1 of 1 (latest)

clear frostBOT
#
Compiler Output
<source>:6:10: fatal error: ncurses.h: No such file or directory
    6 | #include <ncurses.h>// colour library
      |          ^~~~~~~~~~~
compilation terminated.
Build failed
twin isle
#

Need help with terminal game

wild gyro
#

How did you make something like that

#

How did you learn?

strong urchin
#

you should try compiling with address sanitizer, although I am not sure how it will work on your OS but if you have problems reading the resulting errors you can try redirecting stderr to a file. On linux it would look like g++ -fsanitize=address ...etc and run the program with crate 2>errors

strong urchin
#

I can't actually run your game unfortunately due to my terminal but I was bored and compiled it in a virtual machine. Problem is you have off by one error in declaring your coordinate[7][6] and then looping with for int c = 0; c <= 7; c++) this will cause c to loop with the value 0, 1, 2, 3, 4, 5, 6, 7 which is 8 different indexes for a variable with only 7. Typically you write c < 7 instead of c <= 7. The other problem I will leave for you to find but I don't get any sanitizer violations when fixing them both, can't tell if the game is working 'properly' though.

strong urchin
#

not sure I noticed newlines weren't working probably need to change \n to \n\r

#

its carriage return escape sequence

#

oh I have no idea, I don't think that is the only problem I just remember that being a problem when I tried ncurses one time ages ago

#

there is just one other bug but I left it for you to figure out so that you can learn to use address sanitizer

acoustic ospreyBOT
#

@twin isle Has your question been resolved? If so, run !solved :)

strong urchin
#

looks like the problem is your unicode strings. would be annoying to go in and fix it all but that would probably solve the issue and make it playable on linux

#

you could keep your unicode characters but I think you would need to use a unicode version of ncurses, and possibly calling different functions that are specifically for unicode. I haven't ever done this but I am pretty sure unicode is your problem, just don't know for sure all the pieces you need to change

#

its giving you a stack trace of where your program accessed invalid memory, your code is #6 0x558e31291c in inventoryspawn() src/main.cpp:121 in the stacktrace

#

its saying you tried to read invalid memory so you are looking for an incorrect read

#

on line 121

#

so address sanitizer works by checking all of your pointer dereferences

#

in this case craterarity[randomcrate] is the only real dereference that jumps out

#

that i suspect is the issue. Most likely craterarity is null and then randomcrate is c9 causing SEGV on unknown address 0x0000000000c9

#

segv is segmentation fault

#

c9 is the address your process attempted to access initiating the crash

#

i don't actually know if its null, that was just a guess. Looking at your code again it might just be you passed in invalid index which is 99% the cause of a crash on a line where you are indexing an array

#

rand is a c function so most would argue you aren't actually doing things 'correctly' in the cpp way. But in this case you need to think about why your index might not be valid for that array

#

rand isnt the problem its what you do with the value afterwards

#

yeah probably it

#

there are no more address sanitizer exceptions?

#

I am pretty sure I still see at least one problem.

#

look at line 43 and 44 and consider what range of values you could assign the variables

#

you should immediately be suspicious of these lines because they result in an index calculation used on your array

#

are we looking at the same line

#

its in a virtual machine so yea vim

#

yea

#

rand() % 6 will give you 0 through 5 inclusive

#

yup

#

wait where do you use that variable

#

you do have 7 columns so, that one is fine but look at the other rand

#

int randomcrate = rand() % 101;

#

ah I was thinking you were using it to index your array that is coordinates[7][6] but I see now it should be fine, hopefully

#

and I assumed the other one was incorrect too as a result, but they are probably both fine

#

yeah my bad doing a search on your code I don't see it used incorrectly

#

but we should have known that because you aren't getting any more segfaults right?

#

ah, okay then you are getting segfaults

#

but very rarely probably

#

right that was the part I was wrong about

#

I assumed that was wrong since rand() % 101 looks to be wrong

#

cool, that means you have a logical error now which can be harder to track down

#

instead of removing thing[index] you probably will need to make it thing[thingsize-index-1]

#

generally speaking, so you remove the other end of the array.

#

but I am just guessing here

#

did you come from another language before c++?

#

sounds like a python way of thinking

#

your arrays are fixed size so basically you just set the element to zero and treat that value as empty I guess.

#

if you used a c++ datastructure like vector that is basically a python list but with each type being the same instead of mixed types like python array with ["string", 5, etc]

#

you can't really delete things

#

the array is fixed size so all you can do is flag that element as being "deleted" by giving it some special value somewhere

#

such as your bool .freespace you could set it to true I guess

#

if you used a vector you can remove elements from a vector which can actually change size

#

thats deep, but yeah maybe you are on to something

#

oh yeah, definitely. There is a lot haha. But anyways glad I could help

strong urchin
#

I didn't do anything and never fixed it. I just see the symbols like M-b~T and immediately it looks like that is a way the terminal is handling some unicode symbol

#

and notice the other ascii symbols are just fine so you can see current: 0 in that output and other things

#

no you can use unicode characters you just need to use a unicode version of ncurses probably

#

but are you on linux? I thought it was working in your ide

#

I wouldn't worry about it unless you really want to use it on linux or share it with somebody that uses linux. I can't tell you how to solve it but I can tell you its most likely a unicode problem. My answer is gonna be a copy paste from google so yea.

#

no worries

acoustic ospreyBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.