Author |
Topic: Arrays and REDIM (Read 719 times) |
|
datwill
Guest
|
|
Arrays and REDIM
« Thread started on: May 4th, 2015, 7:27pm » |
|
In the LBB help documentation, it says: Quote:You can create three- (and more) dimensional arrays using DIM, for example DIM array$(1,2,3,4), but you cannot subsequently resize the array using REDIM (you can, however, use REDIM with the original dimensions simply as a means of emptying the array). |
|
Does it mean you can't redim ANY array (i.e. 1D, 2D ext.), because I've encountered some issue with my main menu of my game (I try to re-dimension a 1D array, but it seems to clear the array...). Or does it mean you cannot redim 3D+ arrays but can with 1D and 2D?
|
« Last Edit: May 4th, 2015, 7:28pm by datwill » |
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Arrays and REDIM
« Reply #1 on: May 4th, 2015, 10:10pm » |
|
on May 4th, 2015, 7:27pm, Daniel Atwill wrote:Does it mean you can't redim ANY array (i.e. 1D, 2D ext.) |
|
The documentation is correct. 1D and 2D arrays can be REDIMmed (as is of course essential for compatibility with LB 4.04) but 3D-or-greater arrays - which LB4 doesn't support so there's no compatibility issue - can't.
Quote:I try to re-dimension a 1D array, but it seems to clear the array... |
|
REDIM is supposed to clear the array, which is why it says it can be used to clear (but not change the dimensions of) a 3D array.
Richard.
|
|
Logged
|
|
|
|
tsh73
Full Member
member is offline
Gender:
Posts: 210
|
|
Re: Arrays and REDIM
« Reply #2 on: May 5th, 2015, 07:18am » |
|
There is user-supplied RedimPreserve at Passing Arrays
|
|
Logged
|
|
|
|
datwill
Guest
|
|
Re: Arrays and REDIM
« Reply #3 on: May 5th, 2015, 11:01am » |
|
Well yes, I guess it does clear it, but I do include code to fill it with appropriate file information after redimming it, but it comes out as clear in the combobox (which displays this info) in my main menu. There is the error of "Bad use of array" with the combobox (which means it is empty, i.e. no files found, which I will fix), but say I do have an item in the array, the combobox comes up with nothing in it (when you click the dropdown arrow, no item is present). Do any of you know why this could happen? I just tested some more code to create a file before the game crashes, but I still come up with this weird error. Here's my whole code (which there probably will be multiple errors lurking around): 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$, iconHandle
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
open dd$+"data\extra\credit and copyright.txt" for input as #msg
while eof(#msg)=0
input #msg, holder$
if returnFeedCheck <> 0 then creditMsg$ += chr$(13)
creditMsg$ += holder$
returnFeedCheck += 1
wend
creditMsg$ += chr$(13)+chr$(13)+"You can find a better version of this list in the file entitled credits and copyright.txt in the data\extra folders.": close #msg
BackgroundColor$ = "160 96 52"
dim gameFilesInfo$(9, 9): dim fileList$(0)
[mainMenu]
gosub [refreshFileList]: refreshComboBoxFlag = 1
WindowWidth = 363: WindowHeight = 260
UpperLeftX = int((DisplayWidth-WindowWidth)/2): UpperLeftY = int((DisplayHeight-WindowHeight)/2)
button #main.default, "Play (Enter)", [gameSetup], UL, 5, 165, 170, 30
button #main.about, "About File", [aboutFile], UL, 180, 165, 170, 30
button #main.delete, "Delete", [deleteFile], UL, 5, 195, 170, 30
button #main.quit, "Quit", [quit], UL, 180, 195, 170, 30
combobox #main.gamefiles, fileList$(), [wait], 5, 135, 345, 30
bmpbutton #main.logo, dd$+"bitmaps\logo.bmp", [aboutGame], UL, 5, 5
open "Awakening" for dialog_popup as #main
hwin = hwnd(#main): #main "trapclose [quit] ; font ms_sans_serif bold 10"
#main.gamefiles "refresh": call applyIcon hwin
[wait]
wait
[aboutFile]
call getFileInfo
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+1)+" have "+word$("??? ????? ??????!,the stone tablet!", profile.secretItem.struct+1, ",")
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_ICONWARNING 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": gosub [refreshFileList]
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]
#main.gamefiles "contents? fileName$"
if val(gameFilesInfo$(0, 0))-1 <> 0 then
for loopVar = 0 to val(gameFilesInfo$(0, 0))-1
if fileName$ = fileList$(loopVar) then
notice "This name has already been used! So Awakening will create the file for you."
open dd$+"\data\"+fileName$+".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
end if
next
end if
if nameOfFile$ = "" then notice "No file selected!"+chr$(13)+"There is nothing selected/typed in the combobox! Type in a file name not used to create a new file called the name typed, or select an existing file in the combobox list.": wait
call getFileInfo
[quit]
close #main
calldll #user32, "DestroyIcon", iconHandle as ulong, r as boolean
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
[refreshFileList]
files dd$+"data\", "*.dat", gameFilesInfo$()
redim fileList$(val(gameFilesInfo$(0, 0))-1)
if val(gameFilesInfo$(0, 0))-1 <> 0 then
for loopVar = 0 to val(gameFilesInfo$(0, 0))-1
fileList$(loopVar) = left$(gameFilesInfo$(loopVar+1, 0), len(gameFilesInfo$(loopVar+1, 0))-4)
next
end if
if refreshComboBoxFlag = 1 then #main.gamefiles "refresh"
if gameFilesInfo$(0, 0) = "0" then
notice "There are no game files in the data directory!"+chr$(13)+"In order to continue, Awakening will need to make one game file."
prompt "What do you wish to call your file?";newFileName$
if newFileName$ = "" then notice "Awakening will quit!": goto [quit]
open dd$+"data\"+newFileName$+".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
end if
return
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 sub
sub getFileInfo
#main.gamefiles "selection? nameOfFile$"
open dd$+"data\"+nameOfFile$+".dat" for input as #file
input #file, profile.point.struct: input #file, profile.itemC.struct
input #file, profile.itemV.struct: input #file, profile.itemB.struct
input #file, profile.itemN.struct: input #file, profile.itemM.struct
input #file, profile.secretItem.struct: close #file
end sub
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Arrays and REDIM
« Reply #4 on: May 5th, 2015, 1:05pm » |
|
on May 5th, 2015, 11:01am, Daniel Atwill wrote:after redimming it, but it comes out as clear in the combobox |
|
I don't see any RELOAD command in your program.
From the LB docs: "If some time later it becomes necessary to change the contents of the combobox, simply change the contents of the array and send a RELOAD command to the combobox".
Richard.
|
|
Logged
|
|
|
|
datwill
Guest
|
|
Re: Arrays and REDIM
« Reply #5 on: May 5th, 2015, 1:25pm » |
|
Dammit, I used refresh instead of reload Well, now I know...
|
|
Logged
|
|
|
|
|