#How to fix my code?

1367 messages ยท Page 2 of 2 (latest)

royal nimbus
#

yeah

compact coral
#

okay so that just moves the problem

royal nimbus
#

:/

compact coral
#

that's still the same thing

#

local memory after return

#

you want the fun answer or the easy answer ๐Ÿ˜›

royal nimbus
#

now the unique ptr error got resolved

#

just fix the return thing

#

both?

#

like

#

i want to hear about both

compact coral
#

the fun answer is chunks should be a unique_ptr not a raw pointer ๐Ÿ˜›

#

the easy answer is to throw in the towel and just use shared_ptr

#

probably instead of unique

#

(and change chunks back to how it was)

#

FWIW I think the code you had was correct on other compilers

#

it seems a weird MSVC bug is stopping it working properly

royal nimbus
compact coral
#

yea std::pair doesn't have move

#

you may have to use the [cid] = value version

royal nimbus
#

i cannot comprehend the error message lmao

#

okay

royal nimbus
compact coral
#

I have no idea at this point

#

I think MSVC compiler is just wrong here

royal nimbus
compact coral
#

I'm an idiot

royal nimbus
compact coral
#

display world

royal nimbus
#

youre not ๐Ÿ™‚

compact coral
#

auto& sylva = planets[playerPlanet];

#

change to this

#

no unique ptr needed on chunks

royal nimbus
#

oops

compact coral
#

(although in it, yes)

#

insert should be fine

#

you can't copy planets

#

or you will get that error

#

but yea, unwind to when that error was causing problems

#

this is what I had building

#
vector<vector<vector<unique_ptr<Item> > > > createChunk(string planet, int x, int y) {
    //TODO:Actually generating terrain
    vector<vector<vector<unique_ptr<Item> > > > a;
    a.resize(256);
    for (int i = 0; i < 255; i++) {
        a[i].resize(16);
        for (int j = 0; j < 16; j++) {
            a[i][j].resize(16);
        }
    }
    return a;
}
struct Planet {
    string name;
    unordered_map<string, vector<vector<vector<unique_ptr<Item> > > > > chunks;
    vector<vector<vector<unique_ptr<Item> > > >& getChunk(int x, int y) {
        string cid = to_string(x) + "," + to_string(y);
        auto a = chunks.find(cid);
        if (a == chunks.end()) {
            chunks.insert({ cid, createChunk(name, x, y)});
            return chunks[cid];
        }
        else {
            return a->second;
        }
    }
#

probably going to call it a night soon

#

but am curious to see what you come up with!

royal nimbus
#

bye

compact coral
#

(do let me know if that works :P)

royal nimbus
#

you need a move obviously

#

but it works

compact coral
#

freaking where

#

lol

royal nimbus
royal nimbus
compact coral
#

whats the create chunk signature?

royal nimbus
compact coral
#

that ampersand is a problem

#

remove it and the move

#

you can't make references to local variables and return them

#

stop it

pale estuary
#

You two will become besties soon yamikek

compact coral
#

no

#

I am going to bed ๐Ÿ˜›

royal nimbus
#

no errors now

compact coral
royal nimbus
#

ah right that debug spanner

compact coral
#

those numbers are indeed the same

royal nimbus
#

i'll stop throwing spanners into the program โค๏ธ

compact coral
#

only took like 6 hours

royal nimbus
#

yeah lmao

#

atleast i learned about unique pointers

pale estuary
compact coral
#

it's on a console so it's not that 3d yet

pale estuary
#

Oh

#

The intrusive thoughts are telling me to make a physics engine ๐Ÿ˜ญ

royal nimbus
pale estuary
#

Maybe I'd actually learn physics once instead of using the formula book thingy

pale estuary
royal nimbus
#

ah right

pale estuary
royal nimbus
#

i changed some stuff

#

it was "air"

#

now its just null

#

have to make that change lmao

#

how do i stop the program from randomly stopping

compact coral
#

stop having exceptions?

#

that's the debugger crashing on an exception usually

#

or it's hitting a break point

royal nimbus
#

oh

#

click continue

#

idk why but it stops on int main

compact coral
#

did you put a break point there?

#

the little red ball to the left of it?

royal nimbus
#

no

pale estuary
#

What does it say when it stops?

royal nimbus
#

nothing

pale estuary
#

Well there should be a breakpoint then?

royal nimbus
#

but now i found out that if i select a nullptr in the cursorAt=0 then it will break

pale estuary
#

Hmm maybe some conditional breakpoint that you accidentally enabled

royal nimbus
#

btw i clicked f11 for build

pale estuary
#

Idk build us ctrl+b by default on VS

#

And running with a debugger attached is f5

royal nimbus
#

oh

#

ctrl+b?

pale estuary
#

iirc that's build

#

Yes

#

(build but does not run it)

royal nimbus
#

very fixed

pale estuary
#

When you press run the ide builds for you and then runs the exe

royal nimbus
#

now i'll just have to do the f key handling

#

and my "job" today is done!

compact coral
#

well good luck! actually going to bed now lol

royal nimbus
#

byw

#

bye

royal nimbus
#

oof solved a hideous bug

#

xxx.content==nullptr is a valid statement

#

but you really intended to write *xxx.content==nullptr

#

atleast the error rate is less than that of javascript(a weakly typed language or something)

royal nimbus
#

phew

#

finally

#

done!

echo saffronBOT
#

@royal nimbus Please do not send executable files

royal nimbus
echo saffronBOT
#

@royal nimbus Please do not send executable files

true reef
#

Yeah, I also found it to be working one more time: #c-help-text message

And we also found a possible answer: #c-help-text message

royal nimbus
#

compile it yourself because wheatly thinks that im sending a virus after that account hacking thing /hj

#

[spoiler]it is not related to the account hacking or anything lol wheatly just hates executables[/spoiler]

compact coral
#

I do not have windows, lol

royal nimbus
#

controls:i j k l for pointer movement

#

b pick up n put down m put down in appropiate slot

#

space wait

royal nimbus
compact coral
#

this kinda sounds like work, what are you actually trying to fix at this point? or are you just wanting a code review?

royal nimbus
#

code review

#

i did the update thing(confusing because its both the minecraft update and the minecraft schedule tick)

#

now there are two new items:a pacemaker and a siren

#

pacemakers schedule themselves as update and update their surroundings

#

sirens change color when updated

compact coral
#

is it supposed to look like this?

#

well it seems to work anyway

#

here is the version that worked for me, if you want some sort of cross platform support

#

I only changed the init function and above besides replacing _getch() with the helper I defined

#

which brings me to my first bit of code review advice, use a library for console IO

#

a TUI library

#

there are a bunch of choices

#

it's very impressive you figured this all out yourself, but use a library for the love of all that is holy

#

Curses, FTXUI, Notcurses, etc.

royal nimbus
compact coral
#

also we have a #1078717238678409369 forum here for code review ๐Ÿ˜›

royal nimbus
#

curses sounds familliar

royal nimbus
royal nimbus
# compact coral

can you press space a few times and verify there is a siren next to the pacemaker?

#

I can't see it clearly

#

if you press space the siren will change color

#

so i can see it(you can also see it)

royal nimbus
#

oh another he didnt come and tell me i should use llvm lol

compact coral
#

only happens once a day

#

I think across all the threads in a channel

royal nimbus
#

ah ok

#

oh

compact coral
royal nimbus
#

yeah i was wondering it was already 1 day

royal nimbus
#

if you move the pacemaker it should not break and the siren if nearby should still function

compact coral
#

I don't know what these things do ๐Ÿ˜›

#

my first part of feedback would be, add more explorable UI

#

this is dwarf fortress for example

#

note it has descriptions and help ui for cammnds

royal nimbus
#

ooh nice okay

#

yeah maybe

#

i'll check curses first

compact coral
#

it also takes up this huge amount of my termianl for I think no reason

#

which is annoying ๐Ÿ˜›

royal nimbus
#

yeah,sorta...

#

I hardcoded it to be 100x50 because i found out that it worked on my powershell and my screen res

#

with no consideration of cross platform stuff

#

i need to figure some stuff...

#

(not gonna change the 100x50,maybe i will adjust font size or smth)

compact coral
#

you can't adjust the font, that's up to the user's terminal ๐Ÿ˜›

royal nimbus
#

font size

#

not font

#

oops

compact coral
#

yes, up to users terminal

royal nimbus
#

oh

compact coral
#

yea you operating in the very ancient technologies zone

royal nimbus
#

yeah agree

compact coral
#

there are commands to read terminal size last I remember

#

it's okay I found where I can change the W and H

royal nimbus
#

there are commands to read and write terminal size

royal nimbus
compact coral
#
#define W 50
#define H 30

works much better for me ๐Ÿ˜›

royal nimbus
#

๐Ÿ˜›

#

now you get a rte if an item has more than 11 slots or has a name longer than 50 chars

compact coral
# compact coral

if you want me to be able to keep easily running it you should make sure to incorporate these changes so next time you send it I can compile it easily

compact coral
#

there is a lot of code quality concerns here you should work on really

#

what is your goal with this

royal nimbus
#

(oh wait the player has more than 11 slots,trigger the bug by pressing o when selected the blue at sign in the middle of the 0 field!)

royal nimbus
compact coral
#

you should also consider putting it on github

#

so you can track versions and send people links to it

#

instead of copy pasting the file every time

royal nimbus
#

yeah i've never been used to git stuff

compact coral
#

it's pretty straightforward

compact coral
royal nimbus
#

git push
git commit
git outta here
right?

#

lol

royal nimbus
compact coral
#

heh wrong order

compact coral
royal nimbus
#

making a game

compact coral
royal nimbus
#

ahh okay

#

isnt that merge?

#

like

compact coral
royal nimbus
#

push commit merge

compact coral
#

those are three different operations

royal nimbus
compact coral
#

yea, I would say get it in git

#

that's definitly step 1

#

then learn how to add libraries, specifically curses, that's step 2

#

then keep working on it and refactor as you go

#

the git repository supports step 2, because it will be easier for other people compile your thing if you put the libraries in git

#

once you add curses it will be harder for you to drop me a file and have me compile it, cause I need the library too

royal nimbus
compact coral
#

you'll need to download and include the library

#

probably compile it too

royal nimbus
#

cant get ncurses.h in my ncurses installment?

#

i downloaded the newest version from gnu

#

what's make?

compact coral
royal nimbus
#

omfg its so complicated

compact coral
#

you need it in visual studio

compact coral
royal nimbus
#

oh

compact coral
royal nimbus
#

i think i saw cmake yesterday

compact coral
#

so that was a smart idea :p

#

but you probably want "insall ncurses for visual studio"

royal nimbus
compact coral
#

I meant as a search phrase MrshaTired

royal nimbus
#

oh oops

compact coral
#

I don't use windows lol

royal nimbus
#

i cant find 2022,i can only find 2017

compact coral
#

they don't change that much between versions? depends on how the instructions work

royal nimbus
#

found this

#

searched vcpkg

#

it was existing

compact coral
#

vcpkg is probably the right way to install libraries, yes

royal nimbus
#

after putting ncurses-6.5 in my linker

#

it doesn't work

compact coral
#

and also look upt he documentationf or how you are supposed to install this

royal nimbus
#

did not do anything

#

documentation is probably without vs

compact coral
#

how di dyou install ncurses

royal nimbus
#

im doing it

compact coral
#

probably need to go ask someone who is vcpkg pilled for help?

royal nimbus
#

yeah agree

compact coral
#

maybe?

royal nimbus
#

oh wait

#

my program works perfectly without windows.h

#

only exception is that flashing cursor at the origin

compact coral
#

I mean the point of curses is to make it easier to do terminal programming

#

not just to fix the cross platform issues

royal nimbus
#

like

compact coral
#

like I fixed those with the ifdef stuff already

royal nimbus
#

im not doing terminal programming

compact coral
#

you are to draw the screen

royal nimbus
#

im just printing a lot of text with ansi escape

compact coral
#

yes and this is called "terminal user interface" or TUI

royal nimbus
#

ahh okay

#

i should still installl curses and learn vcpkg tho

compact coral
#

yes

#

and git

royal nimbus
#

yeah that link doesn't work

#

its the same one i talked about assuming no vcpkg

#

i mean assuming no vs

#

in retrospect i dunno how this code would help in forcing ansi escape

#

its not using the dwMode for anything lmao

compact coral
royal nimbus
#

yeah dk how to use that in vs

compact coral
#

you don't you run it from a normal command line

#

then this step integrates it with your visual studio

royal nimbus
compact coral
#

you have to start from the beginning

#

and also cmd window like cmd?

#

like I linked you a series of 10 instructions ๐Ÿ˜›

royal nimbus
#

oh ok

royal nimbus
compact coral
#

you may have to use a different TUI library then

royal nimbus
#

hmm

royal nimbus
#

what tui library then

#

why am i x64 windows though

#

(i was not responding bc lunch

#

hello?mason?

royal nimbus
#

@compact coral ?

compact coral
royal nimbus
#

isnt that x86?

compact coral
#

x86 refers to the 32 bit processor, first started with the 8086, sometimes called 386 (hence the X)

royal nimbus
#

ahh okay

compact coral
#

x86-64 is the long name for what you are likely on

#

x86 with 64 bit extensions

royal nimbus
#

ahh okay

#

nice

compact coral
#

most common computer processor instruction set for desktops

compact coral
#

heard good things about it, seems to be on vcpkg

#

tagged x64-windows

royal nimbus
#

hmmm

#

let me see

compact coral
#

I am going to bed soon btw

royal nimbus
#

okay

#

probably not this one...

#

i just need a way to hide the cursor

#

and force ansi escape mode

compact coral
#

you can do it the way you had it before I suppose, the platform specific one

#

just use the ifdefs to support multiple platforms

royal nimbus
#

what ifdefs?

compact coral
royal nimbus
compact coral
#

lol I dunno what windows has

#

do

#ifndef _WIN32
char _getch() {
    return getchar();
}
#endif

instead then

royal nimbus
#

yeah conio.h has its getch

#

either use windows.h and define stuff or not and ifndef

compact coral
#

ifndef is "if not defined

royal nimbus
#

yeah ik

#

also wouldn't your polyfill make it that you need to press enter every time?

compact coral
#

nope, getchar works the way getch does

#

It seems to be working fine without hitting enter as well too

royal nimbus
#

ah ok

compact coral
#

gotta be honest it's been a very long time... like 15 years since I screwed around with this

royal nimbus
#

on my setup getchar did not work without enter

#

so nice polyfill

compact coral
#

it may have to do with the other terminal settings I added

royal nimbus
#

yeah

royal nimbus
compact coral
#

early 30s, independent computer science consultant

royal nimbus
#

oh wow

royal nimbus
#

I did not tamper with display code since the last test(where I was testing about the minus sign feature in the display number function)

#

however now it has no output for some reason

#

the last test worked

echo saffronBOT
#

This question is being automatically marked as stale.
If your question has been answered, type !solved.
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.

royal nimbus
#

!solved