473,657 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OMG please help

Here is the program I just started, The problem i am having is I'm trying to get it to load the image file Sand1 with eval(loader) = pygame.image.lo ad(loader)
because Loader is euqual to "Sand1" but It wont load it. If I set it as loader = pygame.image.lo ad(loader) then it sets the image to the variable loader. So I'm basically trying to set a string equal to a surface variable. I dont want to have to go Sand1 = pygame.image.lo ad("Sand1.bmp" ) for every image because I'm expecting there to be a lot of them when I am done.

So hard to explain if you don't understand what I'm trying to get from it please let me know.


import pygame
from pygame.locals import *
pygame.init()
screen = pygame.display. set_mode( (150,150) )
background = pygame.Surface( screen.get_size () )
pygame.display. set_caption("Em pire Strategy")
pygame.key.set_ repeat(1, 1)
def LoadMaterial():
loader = loading + "1"
eval(loader) = pygame.image.lo ad(loader)
loader = loading + "2"
eval(loader) = pygame.image.lo ad(loader)
loader = loading + "3"
eval(loader) = pygame.image.lo ad(loader)
loader = loading + "4"
eval(loader) = pygame.image.lo ad(loader)
loader = loading + "R"
eval(loader) = pygame.image.lo ad(loader)
loader = loading + "L"
eval(loader) = pygame.image.lo ad(loader)
loader = loading + "T"
eval(loader) = pygame.image.lo ad(loader)
loader = loading + "D"
eval(loader) = pygame.image.lo ad(loader)
loader = loading + "TR"
eval(loader) = pygame.image.lo ad(loader)
loader = loading + "TL"
eval(loader) = pygame.image.lo ad(loader)
loader = loading + "BR"
eval(loader) = pygame.image.lo ad(loader)
loader = loading + "BL"
eval(loader) = pygame.image.lo ad(loader)
loading = "Sand"
LoadMaterial()
pygame.display. update()
repeat = True

while repeat:
for event in pygame.event.ge t():
if event.type == (QUIT):
pygame.quit()
if (event.type == KEYDOWN):
if (event.key == K_ESCAPE):
pygame.quit()
if event.type == MOUSEBUTTONDOWN :
if event.button == 1:
position = pygame.mouse.ge t_pos()
_______________ _______________ _______________ _______________ _______________ _________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsea...egory=shopping

Dec 22 '07 #1
5 1403
Hi Katie,

Please try to write more descriptive subject lines. "OMG please help"
makes you sound like a 14 y.o. breathless school girl who has just broken
a nail. Probably 3/4th of the regulars who *could* help haven't even read
your post because of the subject line.

On Sat, 22 Dec 2007 15:16:53 -0800, katie smith wrote:
Here is the program I just started, The problem i am having is I'm
trying to get it to load the image file Sand1 with eval(loader) =
pygame.image.lo ad(loader) because Loader is euqual to "Sand1" but It
wont load it. If I set it as loader = pygame.image.lo ad(loader) then it
sets the image to the variable loader. So I'm basically trying to set a
string equal to a surface variable. I dont want to have to go Sand1 =
pygame.image.lo ad("Sand1.bmp" ) for every image because I'm expecting
there to be a lot of them when I am done.
99% of the time, when you find yourself wanting to write things like:

sand1 = pygame.image.lo ad("Sand1.bmp" )
sand2 = pygame.image.lo ad("Sand2.bmp" )
sand3 = pygame.image.lo ad("Sand3.bmp" )
....
sand99 = pygame.image.lo ad("Sand99.bmp" )

(or similar) you are going about it the wrong way.

The better way is to do something like this:

sands = [None]
filename = "Sand%d.bmp " # template for the file names
for i in range(1, 100): # start at 1 instead of 0
name = filename % i
sands.append(py game.image.load (name))
Once you've run that code, sands is a list holding all the images you
need.

(Note: The first item of the sands list is None, because lists are
numbered from 0 but your sands are numbered from 1. So we need to make an
adjustment.)

The second half is, how do you use the images?

Instead of writing something like this:
draw(sand1) # I don't actually know how to draw bitmaps in PyGame...
draw(sand2)
draw(sand3)
....
draw(sand99)
you would do something like this:
for i in range(1, 100):
draw(sands[i]) # or whatever the real command is
Does this help?

--
Steven
Dec 23 '07 #2
Steven D'Aprano wrote:
Hi Katie,

Please try to write more descriptive subject lines. "OMG please help"
makes you sound like a 14 y.o. breathless school girl who has just broken
a nail. Probably 3/4th of the regulars who *could* help haven't even read
your post because of the subject line.

On Sat, 22 Dec 2007 15:16:53 -0800, katie smith wrote:
>Here is the program I just started, The problem i am having is I'm
trying to get it to load the image file Sand1 with eval(loader) =
pygame.image.l oad(loader) because Loader is euqual to "Sand1" but It
wont load it. If I set it as loader = pygame.image.lo ad(loader) then it
sets the image to the variable loader. So I'm basically trying to set a
string equal to a surface variable. I dont want to have to go Sand1 =
pygame.image.l oad("Sand1.bmp" ) for every image because I'm expecting
there to be a lot of them when I am done.

99% of the time, when you find yourself wanting to write things like:

sand1 = pygame.image.lo ad("Sand1.bmp" )
sand2 = pygame.image.lo ad("Sand2.bmp" )
sand3 = pygame.image.lo ad("Sand3.bmp" )
...
sand99 = pygame.image.lo ad("Sand99.bmp" )

(or similar) you are going about it the wrong way.

The better way is to do something like this:

sands = [None]
filename = "Sand%d.bmp " # template for the file names
for i in range(1, 100): # start at 1 instead of 0
name = filename % i
sands.append(py game.image.load (name))
Once you've run that code, sands is a list holding all the images you
need.

(Note: The first item of the sands list is None, because lists are
numbered from 0 but your sands are numbered from 1. So we need to make an
adjustment.)

The second half is, how do you use the images?

Instead of writing something like this:
draw(sand1) # I don't actually know how to draw bitmaps in PyGame...
draw(sand2)
draw(sand3)
...
draw(sand99)
you would do something like this:
for i in range(1, 100):
draw(sands[i]) # or whatever the real command is
Does this help?

As Dennis already pointed out I like to use dictionaries in these cases,
so I would use sand = dict() instead of sands = list()
and would do sand[i] = pygame.image.lo ad(name)

Then you can retrieve the content by doing sand[your_number].

--
mph
Dec 24 '07 #3
On Mon, 24 Dec 2007 17:14:58 +0100, Martin P. Hellwig wrote:
As Dennis already pointed out I like to use dictionaries in these cases,
so I would use sand = dict() instead of sands = list() and would do
sand[i] = pygame.image.lo ad(name)

Then you can retrieve the content by doing sand[your_number].
If the keys are just the integers 0...n inclusive, then why bother with
the extra overhead of a dict when you get all the functionality you need
from a list?

--
Steven
Dec 26 '07 #4
Steven D'Aprano wrote:
On Mon, 24 Dec 2007 17:14:58 +0100, Martin P. Hellwig wrote:
>As Dennis already pointed out I like to use dictionaries in these cases,
so I would use sand = dict() instead of sands = list() and would do
sand[i] = pygame.image.lo ad(name)

Then you can retrieve the content by doing sand[your_number].

If the keys are just the integers 0...n inclusive, then why bother with
the extra overhead of a dict when you get all the functionality you need
from a list?
Just a matter of preference in my case no other good reason. Although I
do have a tendency to misuse dict all over the place, but on the other
hand it keeps my stuff readable for others :-)

--
mph
Dec 26 '07 #5
On Dec 26, 1:09*am, Steven D'Aprano <st...@REMOVE-THIS-
cybersource.com .auwrote:
On Mon, 24 Dec 2007 17:14:58 +0100, Martin P. Hellwig wrote:
As Dennis already pointed out I like to use dictionaries in these cases,
so I would use sand = dict() instead of sands = list() and would do
sand[i] = pygame.image.lo ad(name)
Then you can retrieve the content by doing sand[your_number].

If the keys are just the integers 0...n inclusive, then why bother with
the extra overhead of a dict when you get all the functionality you need
from a list?
The keys aren't integers 0...n here, they're 1, 2, 3, 4, L, R, T, D,
TL, TR, BL, BR in the code, so a dict is preferable to a list.

Incidentally Katie: is 'D' a typo? It should be 'B' for consistency.

Also, functions can be passed arguments, and doing so is preferable to
passing information via global variables.

So
def LoadMaterial(lo ader):
...
sand = LoadMaterial('S and')

Is a lot better than

def LoadMaterial():
... code using 'loader'
loader = 'Sand'
sand = LoadMaterial()
Dec 26 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1694
by: Kurt Watson | last post by:
I’m having a different kind of problem with Hotmail when I sign in it says, "Web Browser Software Limitations Your Current Software Will Limit Your Ability to Use Hotmail You are using a web browser that Hotmail does not support. If you continue to use your current browser software we cannot guarantee that Hotmail will work correctly for you". Please help, this is very annoying. I have been searching for help on
7
3594
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title> </head> <style type="text/css">
7
3278
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that I believe if it's solved, the remaining stuff is easy... my full program until now is here: http://www.geocities.com/tom4_h4wk/progmail.zip the problem is the segmentation fault when main trys to run leficheiro.c.... the *.c2 files are the...
23
3259
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application to create certain textboxes, labels, and combo boxes? Any ideas would be appreciated. Thanks
13
4316
by: Joner | last post by:
Hello, I'm having trouble with a little programme of mine where I connect to an access database. It seems to connect fine, and disconnect fine, but then after it won't reconnect, I get the error "operation is not allowed when object is open" so I take out the line of code: BookDetails.Connection1.Open and it comes up with the error "operation is not allowed when object
1
9623
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
1
54496
PEB
by: PEB | last post by:
POSTING GUIDELINES Please follow these guidelines when posting questions Post your question in a relevant forum Do NOT PM questions to individual experts - This is not fair on them and we instruct our experts to ignore any such PMs completely Be sure to give the version of Access that you are working with and the Platform and OS if applicable.
0
3047
by: 2Barter.net | last post by:
newsmail@reuters.uk.ed10.net Fwd: Money for New Orleans, AL & GA Inbox Reply Reply to all Forward Print Add 2Barter.net to Contacts list Delete this message Report phishing Show original
6
3310
by: jenipriya | last post by:
Hi all... its very urgent.. please........i m a beginner in oracle.... Anyone please help me wit dese codes i hv tried... and correct the errors... The table structures i hav Employee (EmpID, EmpName,DeptID,DateOfJoin, Sal, Addr) Finance (EmpID, Sal) Club (Clubname, EmpID, Fee, DateOfJoin) Leave (EmpID, Date) Department (DeptID, DeptName, NoOfEmployees)...
5
2302
by: tabani | last post by:
I wrote the program and its not giving me correct answer can any one help me with that please and specify my mistake please it will be highly appreciable... The error arrives from option 'a' it asks for user name, check in the system but does not return the correct answer please help me with it. or if you have better way of doing it would you please mind to tell me.. thanks.. #!/usr/bin/perl -w #use Getopt::Std;
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8825
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1611
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.