Since last night I was tinkering with some code and couldn't even make a simple application to draw a white circle on the screen... Here's my current code, please direct me to any mistakes:
If InitKeyboard() = 0 And InitMouse() = 0
MessageRequester("ERROR", "DirectX/SDL could not be properly initialized. Please check your installation.")
End
Else
If OpenScreen(640, 480, 32, "SCREEN") = 0
MessageRequester("ERROR", "An error occured while opening a 32-bit 640x480 screen. This should not happen.")
End
Else
Repeat
ExamineKeyboard()
StartDrawing(ScreenOutput())
Circle(200, 200, 100, RGB(255, 255, 255))
StopDrawing()
Until KeyboardPushed(#PB_Key_Escape)
EndIf
EndIf
"And God caused a deep sleep to fall upon Adam, and he slept: and he took one of his ribs, and closed up the flesh instead thereof; And the spare rib, which God had taken from man, made he a woman, and brought her unto the man"
A little mistake I notice in your code here is where you call the Init..
You are calling as AND, so all need to fail for an error, but in reality, if 1 fails you have a problem.
; changed your inits to OR so only 1 needs to fail to end program, else you may end up with
; app fall down, go BOOM - InitMouse() is not required for this sample btw.. :)
If InitKeyboard() = 0 Or InitMouse() = 0 Or InitSprite()=0
MessageRequester("ERROR", "DirectX/SDL could not be properly initialized. Please check your installation.")
End
Else
If OpenScreen(640, 480, 32, "SCREEN") = 0
MessageRequester("ERROR", "An error occured while opening a 32-bit 640x480 screen. This should not happen.")
End
Else
Repeat
a+b
If a>100
b=-1
EndIf
If a<1
color=Random(RGB(255, 255, 255))
b=1
EndIf
; dont forget to clear your screen before drawing on it again
ClearScreen(#Black) ;comment this out & you will see why
ExamineKeyboard()
StartDrawing(ScreenOutput())
Circle(200, 200, a, color)
StopDrawing()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
EndIf
EndIf
;************************************
;*** INITS
;************************************
If Not InitSprite()
MessageRequester("Error","No DX, man!")
End
EndIf
If Not InitMouse()
MessageRequester("Error","No Mouse, man!")
End
EndIf
If Not InitKeyboard()
MessageRequester("Error","No Keys, man!")
End
EndIf
If Not OpenScreen(640, 480, 32, "SCREEN")
MessageRequester("Error","No Screen, man!")
End
EndIf
;************************************
;*** MAIN
;************************************
so, Irene, except the "And" your code is fine, just leave out the "Else" and put the "EndIf" right there...
@Kaeru Gaman: I do all my error-checking at the start too, but I compress
it all down into one small block. For your example, I'd just do it like this:
If Not InitSprite() Or Not InitMouse() Or Not InitKeyboard() Or Not OpenScreen(640, 480, 32, "SCREEN")
MessageRequester("Error","App couldn't start, please try again.")
End
EndIf
I know this doesn't explain exactly WHY it couldn't start, but I don't care for specifics.
PB wrote:@Kaeru Gaman: I do all my error-checking at the start too, but I compress
it all down into one small block. For your example, I'd just do it like this:
If Not InitSprite() Or Not InitMouse() Or Not InitKeyboard() Or Not OpenScreen(640, 480, 32, "SCREEN")
MessageRequester("Error","App couldn't start, please try again.")
End
EndIf
I know this doesn't explain exactly WHY it couldn't start, but I don't care for specifics.
If Not (InitSprite() And InitMouse() And InitKeyboard() And OpenScreen(640, 480, 32, "SCREEN"))
MessageRequester("Error","App couldn't start, please try again.")
End
EndIf
If Not (0 And 0 And 1 And 1)
Debug "Error"
Else
Debug "No errors"
EndIf
You could test with any combination of 0 and 1.
"And God caused a deep sleep to fall upon Adam, and he slept: and he took one of his ribs, and closed up the flesh instead thereof; And the spare rib, which God had taken from man, made he a woman, and brought her unto the man"
For n=0 To 15
;If Not ((n&1) And (n&2) And (n&4) And (n&8))
If Not (n&1) Or Not (n&2) Or Not (n&4) Or Not (n&8)
Debug Str(n)+ "-> Error"
Else
Debug Str(n)+ "-> No errors"
EndIf
Next
as you can see, the And version works properly, the OR version does not.
after all, I better like seperate iffing.
when InitSprite() fails, an OpenScreen() will not just attempted, wich clearly makes sense.