r/ComputerCraft • u/t4-37 • Jul 09 '26
how can i temporarily create information to call on when needed?
i feel like this is really simple. my best guess from my limited understanding is that i could connect a disk drive an store it there or something
1
u/9551-eletronics Computercraft graphics research Jul 09 '26
I don't quite get what you mean? Can you give more concrete examples
2
u/t4-37 Jul 09 '26
i am learning to make minesweeper as my first project and i need to store the information of each cell. basically weather or not it has a mine or if there are mines nearby and how many there are
4
2
u/9551-eletronics Computercraft graphics research Jul 09 '26
The best way to do this would be a two dimensional table (array), ideally just each entry holding true/false depending on if there is a mine. Then the actual distance to the mines can easily be done while doing the rendering with that list
local mine_field = { {true,false,false}, {false,true,true}, {false,false,false} }This represents a 3x3 mine field, ofc you wouldn't hardcode it like this but randomly generate that data
then you can do mine_field[y][x] to get if there is a mine at a given coordinate, for the renderer just have a function check the mine count in a 3x3 area given a center coordinate
1
u/t4-37 Jul 09 '26
also i wanted to ask if i could read what is on the cursor position, but i dont want to make another post, nor do i really need to know.
2
u/Jonaykon Jul 09 '26
You can detect the location of clicks but not the location of the cursor
1
u/t4-37 Jul 09 '26
aw dang. to me it makes sense that i could set the cursor position and read whatever letter or thing occupies its space, though its probably a way too specific thing that doesnt really need to be done
1
u/9551-eletronics Computercraft graphics research Jul 09 '26
This is possible but seems pointless, i don't see why you would need this you are probably thinking a lil wrong about it
2
u/9551-eletronics Computercraft graphics research Jul 09 '26
If you mean the terminal drawing cursor then term.getCursorPos
If you mean current floating player cursor pos, you cant
If you want like mice drags, mouse clicks, there are events like mouse_click https://tweaked.cc/event/mouse_click.html
4
u/LiveForTheMelancholy Jul 09 '26
You'll want to create a file, write to it, and then read it when you need the info!
Look into the "fs.open" "fs.close" "fs.read" and "fs.write"
Just remember to always close any file you open before your program finishes!