[Tutor] Pygame related question

diliup gabadamudalige diliupg at gmail.com
Sun May 25 09:18:40 CEST 2014


I need to random pick a pygame sprite from a sprite class.
The random module does not allow this to be used on a group.
Is the shortest way to raed in the attributes thatr I need into a list and
then random pick that or is there a shorter way? Sample code is given below.

                        scalelist=[]
                        for scale in all_scales:
                            scalelist.append( [scale.name, scale.scaletype]
)

                        scale = random.choice(scalelist)

where all_scales is a sprite class with 45 objects.
I append the 2 attributes of each sprite to a scalelist with the above
function and then random pick an item from the scalelist.

Is this the shortest way?

Thank you to all in advance.

-- 
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**********************************************************************************************
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**********************************************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140525/36a4ec7c/attachment.html>


More information about the Tutor mailing list