#๐ Need Help Refactoring
1231 messages ยท Page 2 of 2 (latest)
wont ask questions about it dw
im just curios
u can ask it i dont mind
but this help thread should prob be focused more on python code

thats why i dont ask lol
back
back with coding problems ? 
i watched to vid twice
wasnt coding
gonna code now
i will code this addItem thing then goto bed
i wonder what should i call tommorows thread ๐
Need Help Refactoring, The Sequel
im coming up with such complicated ways to make this work when it can be done way easier
Well:
Time: 100%
Message: 62.5%
bro did you really keep track of that
last one was 12 hrs
ya can post what ya trying ya know
im trying to use the same if slot is not none logic for the new system
while quantity > 0:
# fullstacks = quantity // maxs
# extrastack = quantity % maxs
# if extrastack > 0: totalstacks = fullstacks + 1
# else: totalstacks = fullstacks
slot = self.findFreeStackSlot()
if slot is not None:
current = (inventory[slot][item])
available_space = maxs - current
add_qty = min(quantity, available_space)
inventory[slot][item] = (current + add_qty)
quantity -= add_qty
else:
slot = self.findEmptySlot()
if slot is None:
print(f"No free slot available for remaining {quantity} of '{item}'.")
return False
add_qty = min(quantity, maxs)
inventory[slot] = {item: (add_qty)}
quantity -= add_qty
comments are new code
rest is old
# if extrastack > 0: totalstacks = fullstacks + 1
# else: totalstacks = fullstacks
btw u can do a funny trick here to simplify this
Go to the forum page and you can see the post time and message count
The message count display cap at 100k message (reason ik is I have a 100k+ message post)
...
it might not be as readable but bool inherits from int
so anything that int can do bool can do too

u mean if extrastack > false?
The method to get the real message count may or may not(I am not disclosing this to get ban) violate the ToS so I am not disclosing how either
false evaluates to 0 yes
. . .
wdym then
if extrastack > 0:
totalstacks = fullstacks + 1 # if extrastack is True this runs
else:
totalstacks = fullstacks # if extrastack is False this runs
this code ya wrote right
ya
if extrastack > 0:
totalstacks = fullstacks + 1 # if extrastack is True this runs
else:
totalstacks = fullstacks + 0 # if extrastack is False this runs
if i wrote it like this it changes nothing does it

well since True evaluates to 1 and False evaluates to 0
My rough estimate is 813431
can ya guess where this going 
kinda..
100% didnt use a bot to count it
-_-
Actually I didn't
101%
huh
ye he counted manually
im curious now
I just imaginate the result
hes a good boy
!e
print(True + True)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
2
somenumber
1+0 is still 1
cause false evaluates to 0 ye
is there somehting here that im not understanding?
or youre just trying to teach me that bools can be used as ints too
just this ye

i knew that
cause u can do some funny stuff with it
but still, thanks
The only thing I'm going to say is gui
like?
if extrastack > 0:
totalstacks = fullstacks + 1 # if extrastack is True this runs
else:
totalstacks = fullstacks + 0 # if extrastack is False this runs
totalstacks = fullstacks + extrastack > 0

its most likely not as readable
but ye its a funny trick u can do
I mean why the else branch?
wow
Or just demonstration purpose
yea its not readable but i undersatnd it
nah the else is needed here
Nvm blindness issue ig
that was a cool one
we made this whole thing
into:
fullstacks = quantity // maxs
extrastack = quantity % maxs
totalstacks = fullstacks + extrastack > 0
not quite
we still have to add other stuff to make it work
but it was intresting indeed
here is anotehr funny thing u can do in python
totalstacks = fullstacks + 1 if extrastack > 0 else 0
totalstacks = fullstacks + [0,1][extrastack > 0]
or this

anyways
somewhat esoteric offtopic
my biggest hint for ya on how to simplify this is just
for slot in range(max_slots):
makes no sense
lmao
do u know about
self.findFreeStackSlot() and self.findEmptySlot()?
idk difference btw the 2
A slot that is empty and a slot that have a item entry with no item?
self.findFreeStackSlot() returns that slot
Oh well
and self.findEmptySlot() is self explanatory
def findEmptySlot(self):
inventory = self.path
for index, slot in enumerate(inventory):
if "air" in slot and (slot["air"]) == 0:
return index
return None
def findFreeStackSlot(self):
inventory = self.path
item = self.item
for index, slot in enumerate(inventory):
if item in slot and (slot[item]) < maxs:
return index
return None
Is "air" actually an item? Otherwise why count amount of air?
Hmm
Should just have an item slot call "empty" just in case "air" exist as an item in the future
"empty" is more likely to be an item than "air"

...?
๐
that hell would empty be
the hell would air be .. ?
literally air
lmao
shove air into a bottle and call that item air
that will be air in a bottle
Chemical mixture that can reduce to oxygen, nitrogen, carbon dioxide etc.
๐ซ
anyways
im procastinating too much
ye didnt know any better
unless u using size in json to limit number of items that thing can have
idk why u need stuff in json

nah
useless
"air": 0
i also have:
def clearInventory(inventory):
for slot in inventory:
inventory[slot] = {"air": "0"}
print('Inventory Cleared!')
Hey @next cove!
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
mean the whole storage section
"storage": {
"inventory": [
{
"sword": 1
},
{
"sword": 1
},
{
"log": 99
},
{
"log": 1
},
{
"air": 0
},
{
"air": 0
},
{
"air": 0
},
{
"air": 0
},
{
"air": 0
},
{
"air": 0
}
]
},
"backpack": [
{
"air": 0
},
{
"air": 0
},
{
"air": 0
},
{
"air": 0
}
]
my biggest change was moving from "0"s to int
Just store null maybe? Could be plausible but could also be too complicated
they were everywhere
null is more likely to be a item than fricking stone
json allows null ?

"storage": {
"inventory": [
{"sword": 1},
{"sword": 1},
{"log": 99},
{"log": 1},
{"air": 0},
{"air": 0},
{"air": 0},
{"air": 0},
{"air": 0},
{"air": 0}
]
},
"backpack": [
{"air": 0},
{"air": 0},
{"air": 0},
{"air": 0}
]
i just realized that inventory is more indented
Yes
its not making it red
No, not as an item
yes understood
is null None or unknown?
[null, {"test": 1}]
should be None
will try that
None cause unknown isn't a python type
anyways fix ur json indent
thats cursed
i like this indent
but it automatically turns into this
"storage": {
"inventory": [
{"sword": 1},
{"sword": 1},
{"log": 99},
{"log": 1},
{"air": 0},
{"air": 0},
{"air": 0},
{"air": 0},
{"air": 0},
{"air": 0}
]
},
"backpack": [
{"air": 0},
{"air": 0},
{"air": 0},
{"air": 0}
]
this indent should be more correct

how to achieve that
Well, depends on the configuration
i use vsc
when i do alt shit f
it turns it to like the one i sent
ye dont do that 
auto formatter is good for when u got a really messy file
but also its most likely way over the top
u can always configure it to do what u want tho

this will do it anyways
son.dump(data, file, indent=4)
son is dumping
and thanks for helping me โค๏ธ
ya welcome
ye
โค๏ธ
if you needed any help with irl stuff hmu
u can close this now with !close or native discord close function
we can finally use that feature
after 20h
lol
lmao
iClose
whoops
dropped the !
it turned upside down
my bad
IClose
whoops
the dot fell off
!open
gn lol
!close
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.