Page 1 of 1
How to iterate through IncludeBinary like an array
Posted: Fri Nov 19, 2021 9:31 pm
by OgreVorbis
I have a bunch of numbered files that I want to put in the DataSection with IncludeBinary. They need to be numbered, I'm not just being lazy

The IncludeBinary part is not too annoying, but what is annoying is that I have to CatchImage many many times. If they were stored in files, I could just use a For loop, but I can't figure how to do that with reading the IncludeBinary.
It uses a pointer like: CatchImage(0, ?Digit1)
etc...
Maybe something like this:
Code: Select all
For i = 0 To 10
CatchImage(i, ?Digit + i)
Next
Maybe there is a smarter way? Or maybe a Macro could be used (that's less pure though)?
It is possible for me to do it manually, but it will add a ton of lines to my program and look junky.
Re: How to iterate through IncludeBinary like an array
Posted: Sat Nov 20, 2021 12:07 am
by mk-soft
Only adjust with IncludeBinary and CatchImage ...
Unfortunately, the vtImages no longer works under C-Backend.
Code: Select all
Structure ArrayOfPointer
*pvData[0]
EndStructure
*Data.ArrayOfPointer = ?vtImages
For i = 0 To 4
Debug PeekI(*Data\pvData[i])
Next
DataSection
vtImages:
Data.i ?Image0
Data.i ?Image1
Data.i ?Image2
Data.i ?Image3
Data.i ?Image4
Image0:
Data.i 000
Image1:
Data.i 100
Image2:
Data.i 200
Image3:
Data.i 300
Image4:
Data.i 400
EndDataSection
Re: How to iterate through IncludeBinary like an array
Posted: Sat Nov 20, 2021 1:39 am
by RASHAD
Maybe
Code: Select all
Restore imageBuffer
For img = 0 To 3
Read.i imageBuffer
CatchImage(img,imageBuffer)
Next
DataSection
Image0:
IncludeBinary "d:\Test.tif"
Image1:
IncludeBinary "d:\Test.tif"
Image2:
IncludeBinary "d:\Test.tif"
Image3:
IncludeBinary "d:\Test.tif"
imageBuffer:
Data.i ?Image0,?Image1,?Image2,?Image3
EndDataSection
Re: How to iterate through IncludeBinary like an array
Posted: Sat Nov 20, 2021 8:07 pm
by OgreVorbis
RASHAD wrote: Sat Nov 20, 2021 1:39 am
Maybe
That works! Thanks
That's what I'm going to use, but I wonder if a Macro can put together variable names before execution? Like in my example where I try to concatenate
?Digit + i
Seeing as macros run at compile time, I would think they could construct a variable this way, but I'm not sure if the functionality exists. I don't need it, but I'm just curious.
Re: How to iterate through IncludeBinary like an array
Posted: Sat Nov 20, 2021 10:08 pm
by RASHAD
You are welcome

Re: How to iterate through IncludeBinary like an array
Posted: Sun Nov 21, 2021 9:01 am
by #NULL
OgreVorbis wrote: Sat Nov 20, 2021 8:07 pmThat's what I'm going to use, but I wonder if a Macro can put together variable names before execution?
That's how I understood your original question and I tried with recursive Macro calls and CompilerIf and MacroExpandedCount but no luck so far.
Re: How to iterate through IncludeBinary like an array
Posted: Sun Nov 21, 2021 9:05 am
by #NULL
But you can just create a pb file with the file commands and include that file then
Code: Select all
For i = 0 To 10
WriteStringN("CatchImage(#img_" + i + ", ...)
Re: How to iterate through IncludeBinary like an array
Posted: Sun Nov 21, 2021 9:08 am
by #NULL
You can also use MacroExpandedCount so you don't have to write out manually all the numbers and can use duplicate lines
Code: Select all
Macro cnt
MacroExpandedCount
EndMacro
CatchImage(cnt, 123)
CatchImage(cnt, 123)
CatchImage(cnt, 123)