Automated slot generation problem[solved]

Hello again, I have made the code below, and it works as I wanted, it get the egg texture card for my game slot and generate more 8 copies of it in a way they are organized in a square fashion.

	#automated slot generator and organizer
	def slotGen(self):
		x = 0.33
		xx = 0
		z = 0.46

		#character creation slot button
		holder = loader.loadModel(data.MYDIR + '/../graphics/2d/menus/ccslot')
		holder.hide()

		for i in range(1,10):
			if i == 4: 
				xx = 0 
				z = 0.09

			if i == 7: 
				xx = 0 
				z = -0.28

			self.slotButton = DirectButton(relief = (None), pos = ( x + xx, 0, z ), geom = (holder.find('**/ccslotR'),
							 holder.find('**/ccslotH'),
							 holder.find('**/ccslotH'),
							 holder.find('**/ccslotR')))

			xx += 0.38

Since directbutton create a copy of the model provided in holder, I made this variable(holder) local and I hid the source egg model.

The problem is, how would I acess the exact slot button I want if they all were created as self.slotButton? I´m not much of a programmer, so if I´m doing things wrong, I would be gratefull if you showed the right way, or a better way. The objective is to generate 9 slots based in a egg texture file, and giving me the possibility to control each slot individualy.

Any help concerning this problem is welcome.

Try something like:

self.slotButtons = []
for i in range(1,10):
    ...
    slotButton = DirectButton(...)
    self.slotButtons.append(slotButton)

This creates self.slotButtons[0], self.slotButtons[1], and so on through self.slotButtons[9].

Note that there’s no reason to call holder.hide(). If you never call holder.reparentTo(render2d), it won’t be visible anyway.

David

I see, so we would use python lists to store each slotButtons handlers, and so we would acess it like self.slotButtons[int]. Also I haven´t noticed which if I have not parented holder to anything it would not be necessary to hid it.

Thanks a lot drwr !