I have a problem.......
Blitz3D Forums/Blitz3D Programming/I have a problem.......
| ||
I was typing in the code on Page 42 of the Blitz3D programming Manual, On Bouncing Balls, thus; ; Bouncing Balls Const Ball_Count = 100 Const Key_Escape = 1 Const Width = 640 Const Height = 480 Type Ball Field X,Y Field XSpeed, YSpeed End Type Function CreateBall() b.Ball = NewBall b\X = Rnd (Width) b\Y = Rnd (Height) b\XSpeed = Rnd (-3,3) b\YSpeed = Rnd (-3,3) End Function Function UpdateBall(b.Ball) If b\X < 0 b\XSpeed =- b\XSpeed If b\Y < 0 b\YSpeed =- b\YSpeed If b\X > Width b\XSpeed =- b\XSpeed If b\Y > Height b\YSpeed =- b\YSpeed b\X = b\X+b\XSpeed b\Y = b\Y+b\YSpeed Oval b\X,b\Y,10,10 End Function Graphics Width,Height SetBuffer BackBuffer() For i = 1 To Ball_Count CreateBall Next While Not KeyHit(Key_Escape) Cls For b.Ball = Each Ball UpdateBall b Next Flip Wend End When I ran this code, the compiler gave me a error saying 'Illegal Type Conversion' Please tell me what have I done wrong? |
| ||
You forgot a Blank in Row 15 b.Ball = NewBall is wrong b.Ball = New Ball is right |
| ||
. |
| ||
What are you talking GfK? Nothing to do with the above error Nothing to do? Oh man ... Its a Typeconversion error and that's why it does not run - the ONLY reason why it did not! Insert the blank and it works but you've also missed out all of the EndIf's in UpdateBall() (which will be your next problem). Next wrong statement ... There are NO endif needed because the If in one line is complete without Endif What's wrong here? Do you test when you "Help" someone? Unbelievable to see such a rubbish |
| ||
Calm down RGR... (that's "has nothing to do with", not "don't need to do anything") EDIT: following doesn't apply after all Blitz3D allows block close tokens (EndIf, Wend, Next, etc.) to be omitted if nothing else follows the block before the end of the function. The If structures are not single-line, they are blocks, but the EndIf is optional because End Function is "senior" to it and forces the block closed anyway. I don't know whether this feature is intentional or just a parser bug that never got fixed, but that part of the code is a valid If structure, and it is a block, not inline. However, I second GfK's advice that this really ought to be "corrected" anyway. (Not everything in the manuals is good style, even if it works; e.g. I think some of the examples still use Gosub, which is never a good idea) |
| ||
Yasha (btw. I calm down when I want ... not when YOU think its time) You're both wrong about the Ifs And you are right? what a laugh! Add the endif's and see what you get as a result ... The thing started so easy ... he forgot a blank ... nothing more And what is this now? A mess ... people who think they are *right* but aren't ... statements which confuse the newbies ... This forum gets crazier every day ... I think some of the examples still use Gosub Yes for a good reason ... because it s in many cases faster than to use Functions! Not everyone needs a Nanny to tell him what to do ... especially if the advice is not good! |
| ||
OK, on closer inspection you're right: the If lines are complete inline statements that omit the Then. I guess the indentation is an IDE artifact or something. My comment above doesn't apply. However, this really, really shows that GfK's suggestion (s/EndIf/Then/g, anyway) is good advice. |
| ||
OK, on closer inspection you're right: the If lines are complete inline statements that omit the Then. I guess the indentation is an IDE artifact or something. My comment above doesn't apply. However, this really, really shows that GfK's suggestion (s/EndIf/Then/g, anyway) is good advice. Yasha - for my Blitz3D-programs I use a patched PureBasic-IDE with indentation, folding, autocomplete etc. I always use endif (but not Then this is not needed at all) because its useful for folding and indentation. And I write each statement in one line to have a better view. But that was not the question of the author of this thread The question above was "I have a problem ..." and I found it within 10 seconds ... a missing blank after ... = New ... Its not good if then someone tells rubbish and I have to defend myself ... GfK is wrong in both cases. He cannot take a quick look over the code without testing and blubber rubbish ... We should at least sometimes be a bit serious here... The thread was solved and finished after my first post ... the rest is timewasting and blah blah blah |
| ||
. |
| ||
GFK wrote: RGR who or what do you think you are ... jackass Then think before you write ... because that made you the jackass Don't *correct* people's statements if you are wrong |
| ||
. |
| ||
If you want we can continue somewhere else in German ... hope your grammar is as good then Added: Ha ha ha ... you deleted your dumb statement that I may have some grammar mistakes in my posts. What a hero ... noticed that I may write better English (not my native language) than you German? |
| ||
I give up. No point arguing with idiots. |
| ||
I give up. No point arguing with idiots. After a long evening the first time you are right! |
| ||
I think the indentation is a bit funny with your if statements...makes it hard to read. |
| ||
You have b.Ball=NewBall, where it should be b.Ball= New Ball. |
| ||
You have b.Ball=NewBall, where it should be b.Ball= New Ball. Daniel Mellas Did you read post #2? |
| ||
I don't like these nested if without the extra grammar. Reason. If we take the first one "If b\X < 0 b\XSpeed =- b\XSpeed" On looking at is slowly I can see that it is, "If A Then B" However when I glanced through the code to try and find the error, which gets more likely as the code gets longer I read, "If A and B Then" Which is not that bad a misread, however I knew for some reason I had read it wrong, (because if (b\XSpeed) =- (b\XSpeed) whilst being possible is stupid. Then I made a big mistake, and changed it in my head without rereading it, to, If A Then B Endif OK it wasn't a long time I was confused for, and the error wasn't there any way. The point I'm tying to make is that when you write your code it might seem like poetry, but when someone else reads it, it needs to be like a prenuptial. You need to have made damn sure that what its meant to say it the ONLY way it can be read. PS You need better thread titles, which are in some way indicative of the problem. EG "Problem, Bouncing Balls Manuel Page 42" or "Can I Store Media with EXE?" |
| ||
. |
| ||
If b\x < 0 b\XSpeed = -b\XSpeed EndIf IS If A Then B Edit Which I think makes my point quite well |
| ||
RGR, BUG OFF! Now it's not just I that has a problem with you, moron! LEAVE this poor man's thread alone and go whine and complain somewhere else! |
| ||
@ H&K The problem which Learning5614 had is solved since post #2 Of cause we can add the same solution every day here and add big advice about programming style and it can be done by 50 people and more. But there will be no better solution for the initially problem. And if Learning5614 really needs great advice about how he has to program is not sure. He didn't say ... so whatever followed is nice but does only waste programmers time who expect to get to know something really important in this thread. Unfortunately there is no important additional information in this whole thread besides the note in post #2 that Learning5614 forgot a blank when he typed in the program from that manual. The author of that manual on the other hand was for sure no newbie - so why must everybody use this thread to try to correct his programming style? Or convince others unasked to use their programming style? |
| ||
Der. Lemme think about that for a second... O wait... I know.. TO LEARN! >< You're a selfish no-good git, and I & ALOT of people on here apparently are getting SO sick of your stuck-up crap! You do NOTHING but troll the needy, and I won't sit there and let you do it ANYMORE! GO AWAY! |
| ||
AS I pointed out, I have no problem with it as a programming style UNLESS it needs to be error checked. At the point you ask someone else to help the code needs to be clear, concise and unambiguous, to the error checker, who, when I replied was me. I didn't bother pointing out what was wrong with the code, because despite reasons to assume otherwise, I assumed you where right. (Actuality that's a lie, I did check you were right) |