LB Booster
« Wut da heck? :-/ »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 05:06am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 hotthread  Author  Topic: Wut da heck? :-/  (Read 1499 times)
datwill
Guest
question Wut da heck? :-/
« Thread started on: Apr 29th, 2015, 5:37pm »

OK, I have this issue that whenever I execute my new game to test it, it comes with an error: Not in a function at line 0 (the err code is 7). Do you know what the heck this is? I tried reinstalling LBB and it still came up with this error...
Unfortunately, my code file is too big for this message! sad
I'll try to send it in separate posts if you need it.
User IP Logged

datwill
Guest
question Re: Wut da heck? :-/
« Reply #1 on: Apr 29th, 2015, 5:48pm »

I've found the naughty line in my code with the help of commenting (wink):

loadbmp word$("central_garden_of_eden exit about copy delete file1 file2 file3 file4 file5 help logo play flowers tree_in_the_middle adam_still", loopVar), DefaultDir$+word$("central_garden_of_eden exit about copy delete file1 file2 file3 file4 file5 help logo play flowers tree_in_the_middle adam_still", loopVar)

This is a line which, in a loop, loads all the bitmaps for my game (not all of them, there will be lots more). I'm not sure why it makes the error... The full loop is as follows:

DefaultDir$ = DefaultDir$+"\bitmaps\backgrounds\"
for loopVar = 0 to 15 'the number of bitmaps to load
select case loopVar
case 1 DefaultDir$ = left$(DefaultDir$, len(DefaultDir$)-12): DefaultDir$ = DefaultDir$+"item menu\"
case 2 DefaultDir$ = left$(DefaultDir$, len(DefaultDir$)-10): DefaultDir$ = DefaultDir$+"main menu\"
case 13 DefaultDir$ = left$(DefaultDir$, len(DefaultDir$)-10): DefaultDir$ = DefaultDir$+"sprites\enemies\"
case 13 DefaultDir$ = left$(DefaultDir$, len(DefaultDir$)-8): DefaultDir$ = DefaultDir$+"foreground\"
case 15 DefaultDir$ = left$(DefaultDir$, len(DefaultDir$)-11): DefaultDir$ = DefaultDir$+"items\"
case 15 DefaultDir$ = left$(DefaultDir$, len(DefaultDir$)-6): DefaultDir$ = DefaultDir$+"player\"
end select
' loadbmp word$("central_garden_of_eden exit about copy delete file1 file2 file3 file4 file5 help logo play flowers tree_in_the_middle adam_still", loopVar), DefaultDir$+word$("central_garden_of_eden exit about copy delete file1 file2 file3 file4 file5 help logo play flowers tree_in_the_middle adam_still", loopVar)
next

And, to add more confusion, the line which is bad isn't line 1...
« Last Edit: Apr 29th, 2015, 5:51pm by datwill » User IP Logged

tsh73
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 210
question Re: Wut da heck? :-/
« Reply #2 on: Apr 29th, 2015, 8:18pm »

Try to change "loadbmp" to "print" and see what arguments you pass to "loadbmp".
For me, I don't see any ".BMP" extension in your code
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
question Re: Wut da heck? :-/
« Reply #3 on: Apr 30th, 2015, 08:36am »

on Apr 29th, 2015, 5:48pm, Daniel Atwill wrote:
I'm not sure why it makes the error...

It's unfortunately a misleading error message - sorry about that! What it means is that the first parameter of LOADBMP (the bitmap name) is an empty string. In the specific case of your code, it means that loopVar is out of range (either zero or greater than 16).

The culprit is evidently this line:

Code:
for loopVar = 0 to 15 

which presumably should be:

Code:
for loopVar = 1 to 16 

I still think your code would be easier to read and easier to debug if you loaded the bitmaps one-by-one rather than in a loop:

Code:
    loadbmp "exit",   "main menu\exit.bmp"
    loadbmp "about",  "main menu\about.bmp"
    loadbmp "copy",   "main menu\copy.bmp"
    loadbmp "delete", "main menu\delete.bmp"
etc. 

Richard.
« Last Edit: Apr 30th, 2015, 08:49am by Richard Russell » User IP Logged

datwill
Guest
question Re: Wut da heck? :-/
« Reply #4 on: Apr 30th, 2015, 08:51am »

OH YES! Thanks for that one (I used 0 in the word$() function which is not good)! And also the .bmp extension problem could be an issue. I should learn to be more like you guys, and should see the errors for myself and stop annoying you guys!

And it worked! I still have an issue with filepaths which I will need to clean up, but all's well! Yes, I think I should do them one by one for now, and then when I feel confident that it's done and working, use the loop idea...
« Last Edit: Apr 30th, 2015, 08:59am by datwill » User IP Logged

datwill
Guest
question Re: Wut da heck? :-/
« Reply #5 on: May 2nd, 2015, 1:15pm »

I'm so mad I wonna chuck my laptop across the room! I've had a hard day fixing a dozen errors now after reworking my game (from things like "Mistake" to "Non-existant structure member", which have taken me hours to find), and I've met some stupid sub routine error! "No such variable" at the last few lines and I don't get it (well, it probably means the variables doesn't exist in the routine's scope)!

Code:
'Awakening v1.0.0's first coding day was 24/04/2015. The project was reworked on the 1/05/2015 and has been continued to
on error goto [crash]
nomainwin: struct profile, point as ushort, itemC as ushort, itemV as ushort, itemB as ushort, itemN as ushort, itemM as ushort, secretItem as boolean
global iconDir$, dd$
dd$ = DefaultDir$+"\"
iconDir$ = dd$+"bitmaps\icon.ico"
aboutFlags = _MB_ICONINFORMATION or _MB_OK or _MB_SETFOREGROUND
aboutGameFlags = _MB_ICONINFORMATION or _MB_OK or _MB_TOPMOST
BackgroundColor$ = "160 96 52"
dim gameFilesInfo$(9, 9): dim fileList$(0)
[mainMenu]
call refreshFileList
WindowWidth = 370: WindowHeight = 265
UpperLeftX = int((DisplayWidth-WindowWidth)/2): UpperLeftY = int((DisplayHeight-WindowHeight)/2)
button #main.default, "Play (Enter)", [gameSetup], UL, 5, 160, 170, 30
button #main.about, "About", [aboutFile], UL, 180, 160, 170, 30
button #main.delete, "Delete", [deleteFile], UL, 5, 195, 170, 30
button #main.new, "New File", [newFile], UL, 5, 135, 345, 300
combobox #main.fileList, fileList$(), [files], 180, 195, 170, 30
bmpbutton #main.logo, dd$+"bitmaps\logo.bmp", [aboutGames], UL, 5, 5
open "Awakening" for dialog as #main
hwin = hwnd(#main): #main "trapclose [quit] ; font ms_sans_serif 10"
#main.fileList "selectindex 1": call applyIcon hwin

[files]
#main.fileList "selection? nameOfFile$"
open dd$+"data\"+nameOfFile$+".dat" for input as #file
for loopVar = 1 to 7
    input #file, r
    select case loopVar
        case 1
            profile.point.struct = r
        case 2
            profile.itemC.struct = r
        case 3
            profile.itemV.struct = r
        case 4
            profile.itemB.struct = r
        case 5
            profile.itemN.struct = r
        case 6
            profile.itemM.struct = r
        case 7
            profile.secretItem.struct = r
    end select    
next
close #file: wait

[aboutFile]
aboutMessage$ = "Animation Clip/Progress: ";profile.point.struct;chr$(13)+"Item at key C: "+word$("Sling Shot,Bow,Wand of Levitation,Wand of Mobility,Wand of Mobile Levitation,Tourches,Pendant of Agility,Pendant of Protection,Pendant of Smite,Stone Tablet", profile.itemC.struct, ",")+chr$(13)+"Item at key V: "+word$("Sling Shot,Bow,Wand of Levitation,Wand of Mobility,Wand of Mobile Levitation,Tourches,Pendant of Agility,Pendant of Protection,Pendant of Smite,Stone Tablet", profile.itemV.struct, ",")+chr$(13)+"Item at key B: "+word$("Sling Shot,Bow,Wand of Levitation,Wand of Mobility,Wand of Mobile Levitation,Tourches,Pendant of Agility,Pendant of Protection,Pendant of Smite,Stone Tablet", profile.itemB.struct, ",")+chr$(13)+"Item at key N: "+word$("Sling Shot,Bow,Wand of Levitation,Wand of Mobility,Wand of Mobile Levitation,Tourches,Pendant of Agility,Pendant of Protection,Pendant of Smite,Stone Tablet", profile.itemN.struct, ",")+ chr$(13)+"Item at key M: "+word$("Sling Shot,Bow,Wand of Levitation,Wand of Mobility,Wand of Mobile Levitation,Tourches,Pendant of Agility,Pendant of Protection,Pendant of Smite,Stone Tablet", profile.itemM.struct, ",")+chr$(13)+"You "+word$("don't do", profile.secretItem.struct)+" have "+word$("??? ????? ??????!,the stone tablet!", profile.secretItem.struct, ",")
aboutCaption$ = "About File "+nameOfFile$
calldll #user32, "MessageBoxExA", hwin as ulong, aboutMessage$ as ptr, aboutCaption$ as ptr, aboutFlags as long, 0 as word, r as long
wait

[deleteFile]
calldll #user32, "MessageBeep", _MB_ICONERROR as long, r as boolean
confirmCaption$ = "Are you sure you want to delete file "+nameOfFile$+"?"
confirm confirmCaption$;r$
if r$ = "no" then wait
kill dd$+"data\"+nameOfFile$+".dat": call refreshFileList
#main.fileList "refresh": wait

[newFile]
prompt "Please name your new file";newName$
if newName$ = "" then wait
for loopVar = 0 to val(gameFilesInfo$(0, 0))-1
    if newName$ = fileList$(loopVar) then notice "This name has already been used!": goto [newFile]
next
open dd$+"data\"+newName$+".dat" for output as #newFile
#newFile "0"+chr$(13)+"0"+chr$(13)+"0"+chr$(13)+"0"+chr$(13)+"0"+chr$(13)+"0"+chr$(13)+"0": close #newFile
call refreshFileList: #main.fileList "refresh": wait

[aboutGame]
calldll #user32, "MessageBoxExA", hwin as ulong, creditMsg$ as ptr, "About Awakening!" as ptr, aboutGameFlags as long, 0 as word, r as long
wait

[gameSetup]

[quit]
close #main: end

[crash]
crashMessage$ = Err$+" (Code: ";Err+chr$(13)+"If you are having serious problems visit http://www.awakening_by_datwill310.com!"
crashFlags = _MB_ICONERROR or _MB_OK or _MB_TOPMOST
calldll #user32, "MessageBoxExA", hwin as ulong, crashMessage$ as ptr, "Awakening Crashed!" as ptr, crashFlags as long, 0 as word, r as long
end

sub refreshFileList
    files dd$+"data\", "*.dat", gameFilesInfo$()
    redim fileList$(val(gameFilesInfo$(0, 0))-1)
    loopVar = 0
    for loopVar = 0 to val(gameFilesInfo$(0, 0))-1
        fileList$(loopVar) = left$(gameFilesInfo$(loopVar+1, 0), len(gameFilesInfo$(loopVar+1, 0))-4)
    next
end sub
sub applyIcon windowHandle
    flag = _LR_LOADFROMFILE or _LR_DEFAULTSIZE
    setIconFlag = 0 or 1
    calldll #user32, "GetWindowLongA", windowHandle as ulong, _GWL_HINSTANCE as long, hInst as ulong
    calldll #user32, "LoadImageA", hInst as ulong, iconDir$ as ptr, _IMAGE_ICON as long, 0 as long, 0 as long, flag as long, iconHandle as ulong
    calldll #user32, "SendMessageA", windowHandle as ulong, _WM_SETICON as long, setIconFlag as long, iconHandle as ulong, r as long
end function 


I've tried defining the constants as number literals, defining EVERY variable which is in the last sub, and it's annoying because nothing's worked! This sets the game windows' icon btw.
And also, no offence; but the line numbers the compiler has been chucking at me (literally) all day are inaccurate (several lines out).
« Last Edit: May 2nd, 2015, 1:18pm by datwill » User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
question Re: Wut da heck? :-/
« Reply #6 on: May 2nd, 2015, 2:01pm »

on May 2nd, 2015, 1:15pm, Daniel Atwill wrote:
I'm so mad I wonna chuck my laptop across the room!

I am very sorry that you are so unhappy with LBB. All I can say is that it is free, and you are not forced to use it.

In this particular circumstance the cause of the error is, I'm afraid, quite straightforward:

Code:
sub applyIcon windowHandle
.........
end function 

A SUB must be ended with END SUB and a FUNCTION must be ended with END FUNCTION. But here you start a definition with SUB and you end it with END FUNCTION, which totally confuses LBB.

Quote:
And also, no offence; but the line numbers the compiler has been chucking at me (literally) all day are inaccurate (several lines out).

I don't believe it. The line number will correctly reflect the line at which an error was detected at run time, but that may not always correspond to the line which contained the mistake. It is inevitable that sometimes errors are not detected immediately but only as a result of some subsequent operation.

But as you are so unhappy with LBB I very strongly recommend that you stop using it, and switch to a language in which you have more confidence.

Richard.
User IP Logged

datwill
Guest
question Re: Wut da heck? :-/
« Reply #7 on: May 2nd, 2015, 2:30pm »

No no, I meant I was mad with errors not LBB! I love LBB it's the coolest language ever! Yes, I should've spotted that. I originally use functions, but they weren't working properly so I changed to subs (face=grin kind of!). That answer was both irritating (the mere fact it was so obvious) and helpful (the other fact that I *clears throught* we wink figured the problem out!).
I'm real sorry about the line thing, I was probably *fixing* (i.e. making an irrelevant change to) the code and not fixing the error LBB actually found. In other words, LBB hasn't got a fault with this and I was misunderstanding the error.
« Last Edit: May 2nd, 2015, 2:38pm by datwill » User IP Logged

tsh73
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 210
question Re: Wut da heck? :-/
« Reply #8 on: May 2nd, 2015, 6:56pm »

Richard,
somehow code from reply #5 crashes LBB with Internal error 26
(after Message box telling "Internal error 26" it just closes. I tried run, debug and even create EXE - same error).
Any ideas?

Currently I'm on Win XP home SP3 with 4Gb ram.
EDIT LBB 3.00

Daniel,
no offence, but line "I originally use functions, but they weren't working properly so I changed to subs" really tells you are not know what are you doing. That's actually OK - and normal learning process - if you are realising this.

I could recommend you 2 things.
1) Teddy bear programming. Google around wink
It was conveyed to me in this form:
"Put a teddy bear on your desk. Then stuck, try to explain your programming problem to a bear. Then it starts arguing, go for a walk". (well, talking to actual living person looks less awkward)
2) Then you have obscure error, try to run your program through Liberty BASIC. Who knows, it might complain differently - and it could help you.
« Last Edit: May 2nd, 2015, 7:17pm by tsh73 » User IP Logged

datwill
Guest
question Re: Wut da heck? :-/
« Reply #9 on: May 2nd, 2015, 8:18pm »

Well, I called and defined the function correctly as far as I was aware. Is it true that you cannot call a function by simply typing:
functionName()
assuming that this function was already defined? I tried to (the one I was using required an argument), but it didn't work, and when I *nearly wink* switched to subs it worked. Idk whether I did something wrong or you can't call a function by itself huh...
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
question Re: Wut da heck? :-/
« Reply #10 on: May 2nd, 2015, 8:43pm »

on May 2nd, 2015, 6:56pm, tsh73 wrote:
somehow code from reply #5 crashes LBB with Internal error 26

That's what Daniel was asking about (Error 26 = 'No such variable'). I explained the cause in my reply to him: trying to end a SUB with END FUNCTION, which confuses LBB:

Code:
sub applyIcon windowHandle
.........
end function 

Or have I misunderstood your question?

Richard.
User IP Logged

tsh73
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 210
question Re: Wut da heck? :-/
« Reply #11 on: May 2nd, 2015, 8:49pm »

Richard, it never said to me "No such variable"
It just shows messagebox with title "Error" and text "Internal error 26" and quits.
I just don't like then program quits - how I'll debug it?

Yes I understand sub/function issue. Question is, does LBB supposed to quit in this case?
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
question Re: Wut da heck? :-/
« Reply #12 on: May 2nd, 2015, 8:50pm »

on May 2nd, 2015, 8:18pm, Daniel Atwill wrote:
Is it true that you cannot call a function by simply typing: functionName()

A function returns a value. If you don't want the returned value, then (for example) assign it to a dummy variable:

Code:
    dummy = functionName() 

But if you are throwing away the returned value, why are you using a function?

Richard.
User IP Logged

tsh73
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 210
question Re: Wut da heck? :-/
« Reply #13 on: May 2nd, 2015, 8:52pm »

Daniel,
Quote:
Well, I called and defined the function correctly as far as I was aware. Is it true that you cannot call a function by simply typing:
functionName()
assuming that this function was already defined? I tried to (the one I was using required an argument), but it didn't work, and when I *nearly * switched to subs it worked. Idk whether I did something wrong or you can't call a function by itself

Yes you can't call function by itself.
But again, "function" supposed to return a value. If you need a value, you will never call it by itself - you either store return value or use it (in expression etc)
If you need piece of code that *doesn't* have return value, then you naturally use sub.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
question Re: Wut da heck? :-/
« Reply #14 on: May 2nd, 2015, 9:22pm »

on May 2nd, 2015, 8:49pm, tsh73 wrote:
Question is, does LBB supposed to quit in this case?

What do you mean by "supposed to"?

If you mean "was it a deliberate design decision to quit?" then obviously not. LBB should never report an 'Internal error'; it means something has gone wrong internally and, if it quits unexpectedly, unsaved changes to the program may be lost.

But if you mean "is that what you would expect to happen?" then yes it is. The code of LBB is written in such a way that an END FUNCTION without a FUNCTION will fail with an 'Internal error 26'. There is nothing mysterious about it.

When writing LBB I concentrated on making an error-free BASIC program compile to an error-free executable, as I hope you would expect. Checking that the compiler behaves in a 'helpful' way when there is an error in the BASIC program is much more difficult!

A valid BASIC program is defined by the Syntax and Semantics of the language, and therefore in principle it is possible to test that every aspect of the compiler works correctly (not that I am claiming LBB does). However there is no 'specification' of an invalid BASIC program: the number of possible errors is close to infinite so it is not practical to test what happens in every case.

I have a large suite of test programs which I use to validate each release of LBB. But I don't have a suite of broken programs to test how LBB behaves with them!

Richard.
User IP Logged

Pages: 1 2  Notify Send Topic Print
« Previous Topic | Next Topic »


This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls