Combining Strings for imagename
Blitz3D Forums/Blitz3D Beginners Area/Combining Strings for imagename
| ||
Not a begginner as such, but this is a begginner type question that is really confusing me. Right, I have written a basic Bitmap Font function. Its nothing special, it just reads in the text and then draws the frame of the animimage bitmap font to the screen based on the Ascii code of each letter....just your basic bitmap font function. Now for the strange bit. In my function I am allowed to pass a few things - Function BMP_Text(text$,posx,posy,fontnumber) Now text$ is obviously the string you want to display. posx and posy are the starting locations (it can also do things like right/left/centre justify but I am keeping the example simple) The problem is fontnumber the idea is that I load 3 or 4 bitmaps (as animimages) for each style of font I am using. This is done at the beginning of the code and because they are only small files it doesn't have any hit on the code itself. Now I call each BMPFont1, BMPFont2, BMPFont3 etc The idea is that in the drawimage code I put usedimage$ = "BMPFont" + Fontnumber For count = 1 to len(text$) letter$ = mid$(Text$,count,1) Drawimage usedimage$,100,100,asc(letter$) Next Again the example above is simplified (each letter will overwrite the last in that code I realise) However I get an error saying Image not found, even tho on the debug I can clearly see that usedimage$ is set to BMPFont1 of whatever. How do I pass the name of the image I want to use into my proc? I have tried making usedimage$ global, the Loadanimimage is global etc etc but I can't work it out. I will try and post the 'real' code later tonight, all the stuff above is just off the top of my head whilst in work and thinking about it :) Cheers, Mark |
| ||
The problem i see here is your trying to construct a string that resembles the image handle. An image handle is a number, and assigned to a particular variable.a1 = loadimage("image.bmp") a2 = loadimage("image1.bmp") a3 = loadimage("image2.bmp") a4 = loadimage("image3.bmp") will work fine. What i think your trying to do is... a1 = loadimage("image.bmp") a2 = loadimage("image1.bmp") a3 = loadimage("image2.bmp") a4 = loadimage("image3.bmp") string$ = "a" for loop = 1 to 4 DrawImage string$+loop,100,200 next which won't work, because the image handles are stored within the variables a1,a2,a3 and a4. I'd recommend looking into arrays for what your trying to achieve here :o) |
| ||
You can't use a string to reference a type. In your case you are passing a string (usedimage$) instead of a reference to an image - you are using a string type where you need an image type. Although you read English and can interpret usedimage$ as pointing to an image object, Blitz can't! It references everything by numbers. What you'd have to do is select based on the string such as... BMPFont1=LoadImage("font_1.png") BMPFont2=LoadImage("font_2.png") BMPFont3=LoadImage("font_3.png") BMPFont4=LoadImage("font_4.png") Select Fontnumber Case 1 image_pointer=BMPFont1 Case 2 image_pointer=BMPFont2 Case 3 image_pointer=BMPFont3 Case 4 image_pointer=BMPFont4 End Select DrawImage image_pointer,100,100,asc(letter$) ___ In summary you can't reference objects by name, and you can't use different object typs (strings, images, entities, textures, custom types, etc.) to reference other types. Edit : Ross C's idea of using arrays would be more convenient (though less illustrative!) Dim font_images(5) For n=1 to 5 font_images(n)=LoadFont("BMPFont"+n+".bmp") Next ... DrawImage font_images(Fontnumber),100,100,asc(letter$) |
| ||
^_^ |
| ||
Cheers guys, I understand exactly what you mean (I like the quote that Blitz cant understand English the same way as me :) :) ) I am rewriting this using arrays, I just really wanted it to be tidy and didn't want to add too many case statements, but that may be the way I go if the arrays dont do it. Apologies also for posting in Blitz3d but thats the version I am using (even tho its not a 3d related question as such!) M |
| ||
Why don't you just pass the font image handle into your "Print" function as a parameter? |