Python Forum
How to find the location of an object and object at a given location?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to find the location of an object and object at a given location?
#11
(Jan-29-2017, 03:35 PM)hsunteik Wrote: Everything you said in your last post is absolutely true,but I need to jump to advanced stuff because it will  waste my time by staying or doing easy stuff.
In other words,I want to rush so I can do more advanced thing with python in the future.

Note:I am just a 15 years old boy,that does not know add math or physic yet,and I will be having pt3 this year too.

No school let you jump to advance stuff without learning the basic first.
You always start with the simple stuff and then you advance.

Minecraft does save block data to the harddrive but they do it in chunks.
Minecraft chunksize 16X16X256.
So you need to make a chunkloader and unload chunks not in use.
You can use a database like mysql or make your own.

You need to know matrix math for opengl.
99 percent of computer problems exists between chair and keyboard.
Reply
#12
Thanks for helping ,Windspar.
It help me a bit,but I will still have question to ask.
Reply
#13
Basic.
from random import choice

def generate_chunk():
    chunk = []
    
    for x in xrange(16):
        chunk.append([])
        for y in xrange(16):
            chunk[x].append([])
            for z in xrange(16):
                chunk[x][y].append(choice([1,2,3,4,5]))
    
    return chunk
                
    
def main():
    data = generate_chunk()
    print data[0][0]
    print data[4][5][3]
    
main()
99 percent of computer problems exists between chair and keyboard.
Reply
#14
(Jan-30-2017, 01:51 PM)hsunteik Wrote: The main thing I want to know is how to procedurally create variable name and assign the value to it,please?
Maybe after you answer this question,I can figure out how to solve it myself.

You're not getting an answer to this question because it's a bad question. Python is not set up for procedural creation of variable names. You could do it, but you would have to work against Python to do it. You never want to work against your programming language. If you find yourself doing that, you either need to switch your programming language or switch how you're working.

When you want to do this sort of thing in Python, you should be using a dict. I have a feeling you will next ask how to use a dict to do this. But that's one of the basics people keep telling you that you need to know.

You want to jump to the high level stuff without a foundation in the basics. But then when you try to write a high level application, the application will have a bad foundation because it won't use the basics well. And that will cause problems throughout your application, like the slowness of reading and writing to the hard disk, or constantly fighting against Python to dynamically create variable names.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#15
I haven't read this whole thread, but to just explicitly connect "it's a bad question" and "learn the basics" - if you don't know the basics it's virtually impossible to ask the right questions. Have you ever heard anyone ask a question (sometimes rhetorical) and you know enough about that topic to know that their question itself shows how little they know? Like someone asking, "who is the king of France?" (France does not have a king.)

I think it's good that you want to jump into advanced stuff, and I think that you should keep that mindset, but you also need to learn to pull back when you find that you're going too far. If you don't even know what question to ask, you're gone too far. Pull back. Admirable attitude, but things aren't going to work out well - either you're going to spend all your time not understanding things, or worse, you'll understand just enough to get it really wrong. Learning how to ask a question well is another "basic" skill (super important early on, but will take a long time to fully master) that ties in here.
Reply
#16
(Jan-29-2017, 04:47 AM)hsunteik Wrote: I have two question

1)how to find the object given the location of the object?

Let's say I draw a cube at coordinate x y z ,4 5 3 respectively.
I want Python to print "cube" when I search the coordinate 4,5,3.
How would I do it?
I can use a variable to keep track the coordinate of every object in the game,but I have infinite amount of object generated in the game scene(using infinite procedural generation)

2)how to find the location of the object given the object name?

Note:I am using OpenGL 
Note2:there must be something in OpenGL(or pygame) I can use to keep track of the location of all object in the game scene.
Is there?

You've got the conversation backward.  You don't ask python/pygame/opengl anything.  Because they don't track anything.  You do.  Instead of asking those things a question, you tell them things.  You have some objects, and you tell those libraries where to display those objects.  Nothing moves, unless you tell it to.  So there's nothing in opengl/pygame to track where things are... because you should already have that information.  Otherwise, how are you displaying it in the first place?
Reply
#17
(Feb-03-2017, 07:27 PM)nilamo Wrote: there's nothing in opengl/pygame to track where things are... because you should already have that information.  Otherwise, how are you displaying it in the first place?
It is all procedurally generated ,that is why i dont have the information of where things are.
Reply
#18
(Feb-04-2017, 04:33 AM)hsunteik Wrote: It is all procedurally generated ,that is why i dont have the information of where things are.

You should store that information as you procedurally generate them.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#19
Right, but again, YOU'RE procedurally generating it, right? opengl or pygame aren't procedurally generating a single thing.
Reply
#20
(Feb-04-2017, 12:05 PM)ichabod801 Wrote:
(Feb-04-2017, 04:33 AM)hsunteik Wrote: It is all procedurally generated ,that is why i dont have the information of where things are.

You should store that information as you procedurally generate them.

thanks.i have thought about that before but i just forgot about it. Big Grin
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Rect object penetrates wall on one side Jan_97 4 2,463 Dec-30-2021, 11:08 PM
Last Post: Jan_97
  [PyGame] object has no attribute 'add_internal' djwilson0495 7 7,965 Feb-26-2021, 05:06 PM
Last Post: nilamo
  Location of the objects that are moving rturus 1 2,128 Feb-01-2021, 05:44 PM
Last Post: nilamo
  [PyGame] why the position of the object is different? syafiq14 1 1,904 Nov-24-2020, 03:22 PM
Last Post: metulburr
  [PyGame] object's movement to left leave shadow on the screen Zhaleh 3 3,082 Aug-02-2020, 09:59 PM
Last Post: nilamo
  I can't control the speed of the turtle object Hesper 1 2,489 Apr-10-2020, 01:37 PM
Last Post: deanhystad
  open cv ->pygame: turn image into location Gamedeveloper 1 2,031 Jan-20-2020, 05:00 PM
Last Post: michael1789
  rect object not loading BlueClaw 2 4,109 Dec-11-2019, 04:25 PM
Last Post: BlueClaw
  beginner - object has no attribute gean 2 3,630 Nov-07-2019, 02:02 PM
Last Post: gean
  [pygame] Moving an object at angles SheeppOSU 3 8,501 Oct-24-2019, 08:05 PM
Last Post: SheeppOSU

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020