#๐ Conventions regarding when to make a class
44 messages ยท Page 1 of 1 (latest)
@robust copper
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Can you show some code?
sure, give me a sec
broadly, i want to be running something like this every frame
this is because the camera "moves too fast"
(now obviously there are probably better solutions to this)
This seems much more fitting as a method
but i am curious as to this particular case
so you think a class is fine, storing recent_camera_pos as an attribute?
it should actually be base.camera. base is a global variable storing lots of stuff
this is from a template in Panda3D
which i am very very new to
for context, panda3D is a bit like Pygame except with more 3D. when rendering a scene, mouse actions by default move the scene around. but i find this motion much too fast
no that doesnt sound like overkill, ive defined "get_state()" before.
ok having looked this up a bit, it seems like "one-method classes are bad" refers to when no state is being stored
i would either define it as a normal function or attach it to an "Environment" object
how do you mean?
idk what your code is but you could have an object that represents the world you are programming and define methods for it
i have a big simulation ive made that has class Environment with methods such as get_state, reset, fast_forward etc
if you dont need the class just define it as a normal function
creating a class is the main way of having a "stateful function". especially if you want to have more than one instance of it.
by "stateful function", I mean a function with persistent state between calls.
could be done by just returning the state and storing it
like what, a dict of all the variables in the function?
i interpreted state as location of entities within his game
but yeah a dict could work
the state required is the position of the camera in the previous frame, which happens to be calculated in the previous call of the function
you can just have the previous frame as a variable in the scope where you're calling the function
i am currently calling from global scope
which isnt terrible in pygame/python/pandas3D
this seems to work
it's a bit odd having one instance that i never reference
ok (x+y)/10 is not a weighted average why is this sorta working
gonna have to define " sorta working"
ok still weird but i can probably just figure the rest out myself
working for Pos and not angle (hpr)
!close
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.