Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Need Help with a IFstatement.

Author
Message
Xfighter
13
Years of Service
User Offline
Joined: 8th Feb 2013
Location:
Posted: 8th Feb 2013 17:12
My Ifstatement for my game is not working. I am trying to load a bitmap if a person playing my game hits 1 and load a diffrent bitmap if they hit 2,3,or 4. When I do this code, it loads the bitmap for 2,3,or 4 even when I press one.
Here is the Ifstatment code...
[/code]IF guess = 1
Load Bitmap "F:\Math Game\images\2nd page.bmp"
Endif
If Not guess = 1
Load Bitmap "F:\Math Game\images\Game pag night sky copy 2.bmp
Endif
wait key
[code]
I then tried to replace the bitmaps with print and that made it so it does not work at all.
I am currently trying to make a Math game.
Thank you for your time.
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 8th Feb 2013 20:06 Edited at: 8th Feb 2013 20:08
Try this:



(You have to number your bitmap also!)

D.D.
Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 8th Feb 2013 20:11
Or:




Previously TEH_CODERER.
zeroSlave
17
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 9th Feb 2013 01:47 Edited at: 9th Feb 2013 02:37
Or:
(where 'guess' is a boolean' 1 or 0, true or false)

Or, better yet:

Quote: " I am trying to load a bitmap if a person playing my game hits 1 and load a diffrent bitmap if they hit 2,3,or 4. "

You should use SELECT & CASE for something like this.

Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 9th Feb 2013 05:09
So nice to see so many new faces recently, Welcome to the forums Xfighter!

Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 9th Feb 2013 11:21
@zeroSlave - Definitely the 'select' statement. Sorry, I think I paid more attention to the code than to what was being said. Something I'm often guilty of in real-life.


Previously TEH_CODERER.
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 10th Feb 2013 16:18
I second (or third?) the use of SELECT.

Quote: "I then tried to replace the bitmaps with print and that made it so it does not work at all."

Good job on trying this: getting as much information on screen as possible will help you fix bugs.

^ That's what she said.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 11th Feb 2013 00:12
I would suggest not using bitmaps. Larger files means longer load times. And in your current logic, the player in your game would have to wait for the content to load each time. Make the PNG or even JPG and load all 4 pages from the start and swap between them during the game.

"You're not going crazy. You're going sane in a crazy world!" ~Tick
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 11th Feb 2013 13:49
Jpgs take real long to load compared to PNGs; try it and see. (For textures use DDS files)

Xfighter
13
Years of Service
User Offline
Joined: 8th Feb 2013
Location:
Posted: 11th Feb 2013 17:41
Sadly none of the posts with codes are working. Is there something wrong? Also, I like the 'select code' but it isn't working either. Im thinking about changing my bitmaps to JPG's or PNGs.
I need to still know if thats the best optio with PNG's and the Select. Thanks and hope you post ore suggestions.
Xfighter
13
Years of Service
User Offline
Joined: 8th Feb 2013
Location:
Posted: 12th Feb 2013 17:00
Im trying the Select code and still it is not working.
I changed the code to be the same as the Bitmaps, but it acts as it was when i used the basic IfStatement where no matter what i press it only shows one image and it won't change the Image if you press 3 it will act as it was 1.
Ortu
DBPro Master
18
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 12th Feb 2013 21:06
can you post your current code, including the part where you are taking input and setting the guess variable?

Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 13th Feb 2013 00:31 Edited at: 13th Feb 2013 00:42
Did you take Phaelax's advice and load everything at the start, then just switch between the images?

example:


^ That's what she said.
Xfighter
13
Years of Service
User Offline
Joined: 8th Feb 2013
Location:
Posted: 13th Feb 2013 17:05
Im trying this code now with the Select Statement...


But it is giving me the same problem with some codes ive tried and the problem is that it doesn't load another bit map it just stays there.
My qustion is why it is doing this and also the Images i used are just testing images I had left over.
Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 13th Feb 2013 18:34
The code you've used there wouldn't display anything if that is what you're expecting. You have only loaded a bitmap, not done anything with it.



Does that work for you?


Previously TEH_CODERER.
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 13th Feb 2013 19:04 Edited at: 13th Feb 2013 19:05
@Andrew_Neale
You fixed the problem but not xfighter's poor structure:

OR

In this case you could replace the SELECT with img=guess+1 but I left it in because it wont always be linear like that.

^ That's what she said.
Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 13th Feb 2013 21:38
Whether or not it is bad structure is impossible to say without knowing more about the scenario. It may be that memory usage is more important than waiting a small amount of time for the image to load. It may be that only one of these images is ever needed and this is a one off decision that is made to load just that one. If this was going to be run multiple times and potentially showing a different image each time then yes, your example would be better. I didn't feel it made sense to try and optimise for a particular scenario without knowing it was actually relevant.


Previously TEH_CODERER.
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 13th Feb 2013 22:13
@Andrew
That is good logic but maybe a beginner is not aware of the implications.

^ That's what she said.
Xfighter
13
Years of Service
User Offline
Joined: 8th Feb 2013
Location:
Posted: 20th Mar 2013 16:15
*Update* These were great suggestions, but I couldn't figure out what was wrong so I changed my game so thank you for who ever tried to help. Thanks.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 20th Mar 2013 21:13 Edited at: 20th Mar 2013 21:15
Quote: "Andrew_Neale

The code you've used there wouldn't display anything if that is what you're expecting. You have only loaded a bitmap, not done anything with it: ...CASE 0: LOAD BITMAP "F:\Math Game\images\Welcome to Math-A-..."


It would usually display the bitmap, since that statement by default loads the bitmap into the screen due to the omitted bitmap index and the current bitmap being the screen; but obviously his code does not follow good practice outlined in many tutorials in the site; for some reason people are not checking the tutorials before doing the programming.

ShellfishGames
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 20th Mar 2013 22:52
Quote: "I would suggest not using bitmaps. Larger files means longer load times. And in your current logic, the player in your game would have to wait for the content to load each time. Make the PNG or even JPG and load all 4 pages from the start and swap between them during the game."


Are you sure? I thought de/compressing images might require more time than reading/writing the uncompressed data from/to the HDD. For instance when you record videos with Fraps it saves them uncompressed because it's apparently faster.

Quote: "for some reason people are not checking the tutorials before doing the programming."


Naturally most people want to get their hands dirty as soon as possible without taking into account the theory. While this is not ideal and leads to a lot of additional threads on this board, I completely understand that. Most starters want to make games primarily, and learning the basics of programming is often considered the necessary evil.

Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 20th Mar 2013 23:15
True

Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 21st Mar 2013 08:38
Quote: "It would usually display the bitmap, since that statement by default loads the bitmap into the screen due to the omitted bitmap index and the current bitmap being the screen"


In the post from 13th Feb 2013 23:05 he'd specified a bitmap index of 1 which is where my comment originated from. Just felt the need to defend my honour.


Previously TEH_CODERER.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 21st Mar 2013 10:04 Edited at: 21st Mar 2013 10:06
Good grief, I didn't spot that.

This is where tutorial reading is so vital because the documentation for Load Bitmap is not very good:

Quote: "Load Bitmap

The picture file must be of the BMP, JPG, TGA, DDS, DIB or PNG format. You can optionally provide a Bitmap Number between 0 and 32. Once you have loaded the picture file successfully, you can use the specified bitmap number to modify and manage the bitmap. The bitmap number should be specified using an integer value. "


No where in there does it explain the events that occur when the command is used. Wish I had the time contribute some documentation, would be nice for newcomers.

Login to post a reply

Server time is: 2026-07-07 06:23:52
Your offset time is: 2026-07-07 06:23:52