[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] stumped by basic python
On 1/6/06, Knapp <magick.crow@xxxxxxxxx> wrote:
> I know this must be a dumb Noob question but I am stumped.
>
> I want to rewrite this so that I can put it all in a loop calling on the
> data in the list to make the functions and fill in the data. What I don't
> know if how to come up with "sunModel" and the "mercuryModel" etc in the
> loop based on the list names and then set the data to that. Make sense? The
> way I started was to hand code it but that is crazy.
>
> Thanks
>
> Douglas
>
> sol1=(('sun', 'sunmap.jpg', 139),('mercury'. 'mercurymap.jpg', 2.4297),
> ('earth', 'earthmap1k.png', 6.378), ('moon', 'moonmap1k.png' ,1.738))
>
> sunModel = loader.loadModelCopy("BasicPlanet2.egg")
> sunModel.reparentTo(render)
> sunModel.setScale(139)
> tex = loader.loadTexture('sunmap.jpg')
> sunModel.setTexture(tex,1)
You have a few options.
d = {}
for name, filename, scale in sol1:
model = loader.loadModelCopy("BasicPlanet2.egg")
model.reparentTo(render)
model.setScale(scale)
model.setTexture(loader.loadTexture(filename), 1)
d[name] = model
This will give you a dictionary (d) which has keys which are the
names, and values which are your models. There are lots of other
solution. You might also want to look at help(setattr).
-Sw.