Problem accessing type-parameter in list...

BlitzMax Forums/BlitzMax Beginners Area/Problem accessing type-parameter in list...

NickFalk(Posted 2007) [#1]
Hi there, after some generous tips from you lot I'm trying to use tlists to implement aliens in my [soon to be] legendary shmup. I did generate some code first just to see if I had the syntax sorted out, and thought I had the whole list thing figured out. I am however unable to get the following code to work:
Local antalaliens : Int = 6	' define number of aliens
		Local alienx : Int = 200
		Global blomswarm : TList = CreateList()
		For counter = 0 To antallaliens-1
			Local alien : talien = New talien
			alien.x = alienx	
			alien.y = 200
			blomswarm.addlast(alien)
			alienx = alienx + 60
		Next'counter

For swarm1 : alien = EachIn blomswarm		
				DrawText swarm1.x '"here there be problems"
			Next


trying to execute the following code results in a "Missing function parameter 'x'" compile-error. (And yes the type talien does have an x-field).

Anyone? Thanking you all in advance for your trouble.


GfK(Posted 2007) [#2]
Doesn't appear to be anything wrong with your type handling. Your DrawText syntax is incorrect though.
DrawText text,x,y

The parameters are not optional. You're giving it a var to use as 'text', but there's nothing for X or Y, hence the error message.


NickFalk(Posted 2007) [#3]
Thanks!
Good thing this is the "Beginners Area". :)


SculptureOfSoul(Posted 2007) [#4]
Well, you got the hardest part of the above code right :).

Just an FYI - it's a lot easier to read code of the following format:

myalien:talien

than it is with the spaces. The spaces just further separate (both literally and figuratively) the variable from its type, and inhibit the "flow" of reading the code. I guess this is just my opinion and I don't want to speak for others but from reading others code I'd say they agree. A minor issue that you're free to disregard. :)


NickFalk(Posted 2007) [#5]
Thanks for the tip SculptureOfSoul. I've actually developed the habit seperating the lines as I personally find it easier to read (I find it easier to actually make out the variabel names this way). But each to his own I guess. ;)


TomToad(Posted 2007) [#6]
Change
For swarm1 : alien = EachIn blomswarm		
				DrawText swarm1.x '"here there be problems"
			Next

to
For swarm1 : talien = EachIn blomswarm		
				DrawText swarm1.x '"here there be problems"
			Next



TomToad(Posted 2007) [#7]
Also noticed this mistake
Local antalaliens : Int = 6	' define number of aliens
		Local alienx : Int = 200
		Global blomswarm : TList = CreateList()
		For counter = 0 To antallaliens-1

antalaliens is not spelled the same therefore, you are only going to get one alien created in your list. If you use Strict or Superstrict at the top of your source, errors like this will be caught.


GfK(Posted 2007) [#8]
TomToad's comment about changing 'alien' to 'tAlien' is correct, too. In his corrected code, he still has the DrawText syntax incorrect though. Thought I'd mention it to avoid any confusion. ;)


NickFalk(Posted 2007) [#9]
Thanks noticed that antallaliens mistake after about 30 minutes of hairpulling myself...


Dreamora(Posted 2007) [#10]
hairpulling?
why hairpulling?

If you program in BM and do not use Strict / Superstrict you will be going to have some annoying issues anyway and with those two that would have been very obvious as the compiler will throw you against it ^^


NickFalk(Posted 2007) [#11]
Well I DO need a haircut...

Probably should delve into the strict / superstrict thingy though as it would have saved me loads of time.

Will clean up the code and give it a try...


CS_TBL(Posted 2007) [#12]
I demand a strictness setting in the Bmax .ini file which I can set to superstrict :P

And there should be uberstrict for case-sensitive variablenames too!


Sledge(Posted 2007) [#13]
For swarm1 : talien = EachIn blomswarm


TomToad's comment about changing 'alien' to 'tAlien' is correct, too.


That prefixing types with 't' has to be one of the ugliest and most unnecessary (given that you've got a list of types to the right of your source code in the IDE) coding conventions I've ever seen. (And he said 'talien' not 'tAlien', which makes things more obfuscated rather than less, to my mind.) I don't see why anyone should feel obligated to adopt it.

Now obviously it's very handy to make types obvious when posting source code that you want help with because the easier it is to suss what's going on the more likely it is you'll get some assistance, so it might be a good idea to add a type identifier when posting even if you don't use one when coding. But doesn't a suffix make more sense? Because you identify ints and floats etc with suffixes, so that's already the standard (with which Timages and Tlists are already inconsistent... whoops!), and you also wouldn't need to recapitalize your variable names (ie from bigAlien to tBigAlien) -- editing in a suffix is less of a faff, right?

EDIT: Sorry, I've gone off on one a bit, there. I just find 'You SHOULD do THIS' posts mildly irritating because, well, should he really? Scratch that last bit, for obvious reasons - but I'd still like the above convention (tThis, tThat) explained to me.


And there should be uberstrict for case-sensitive variablenames too!


I would like that. Although I use very descriptive variable names so have adopted the practise of copying and pasting 'em so they're always right. It's not intellisense, but hey...


Brucey(Posted 2007) [#14]
I blame *all* the examples, as they don't mention Strict/SuperStrict.

In fact, unless you know about them, the chances of stumbling across them in the documentation aren't great.

Sure, it mentions Strict in the "BASIC Compatibility" section, but I don't think I've seen anywhere else that talks about SuperStrict.

Yeah, I know the documentation is generally sucky.. :-p

There should probably be a sticky or something... "Important - Use Strict / SuperStrict"

...explaining why they are good things to use.

:-)