How do I check multiple items in a TYPE
Blitz3D Forums/Blitz3D Beginners Area/How do I check multiple items in a TYPE
| ||
Say I have..TYPE fish Field color end type goldfish.fish = new fish shark.fish = new fish nemo.fish = new fish goldfish\color = orange nemo\color = orange shark\color = grey Now, say I have several hundred fish. How can I go through and find which are orange without checking each one by name (eg, if nemo\fish=orange then)? TYPE won't let me use FISH(1).FISH = New Fish so I can't do a loop to check them all. Basically, I'm trying to write a function which creates new items on the fly (up to a maximum of 99), and assigns them each an ID number. Hence, I don't want to have to know the names of, and do a manual check on each one. The EACH command doesn't seem to apply here, and if it does, maybe I'm mis-reading the manual? :) Any help would be appreciated! +BlackD |
| ||
Ooooh.. figured this one out. :D I'm totally mis-using the TYPE command. EACH does indeed apply if used correctly. *bangs head on desk* ... *repeatedly*. Sorry for the trouble folks. :) +BlackD |
| ||
Example as applicable if my understand of type is correct: [code] Type seacreature Field name Field color End Type fish.seacreature = new seacreature fish/name goldfish fish/color orange fish.seacreature = new seacreature fish/name nemo fish/color orange fish.seacreature = new seacreature fish/name shark fish/color grey for fish.seacreature = each seacreature c = fish/color:n = fish/name if c = orange then print n + "is orange!" next [/Code] Am I on the right track? :) +BlackD |
| ||
Yep, exept you have to do something like this:type seacreature field name$ field color$ end type fish\name$ = "goldfish" fish\color$ = "orange" The "$" on the end of the variable indicates that it is a 'string', which is a collection of letters. You then can do If fish\color$ = "orange" To check if it's orange or not. |
| ||
It might be better on memory and could be faster if you use constants rather than strings ORANGE=1 as opposed to "orange" |
| ||
Oh, yeah - that was just an example. I'm using it for developing my GUI so I can declare window data in the same way VB does. eg, main.height, main.visible, etc. :) Thus I can write programs externally in my own scripting language and the Blitz program is simply an interpreter. Custom functions make this a breeze, etc - CreateWindow(handle,[title$],[x],[y],[width],[height]) to create a window in the GUI which is thereon referred to by the HANDLE in the scripting language. Meanwhile in Blitz it's assigned a xxxxx1.window (module) number which I (or anyone using the scripting language) never need to know. By using TYPEs, I can call the command "CreateWindow(About)" to automatically create a default-attributed window in the centre of the screen, and then rather than having to know a DIM array number to change data, I can simply do "about.title$="my about box" in my script, or any other changes later on, and the interpreting functions in my Blitz program handle all the heavy stuff. Herein lies the beauty of TYPEs which I never fully understood until about 5 hours ago. They do all the hard work for you. :) +BlackD |