English Amiga Board

Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

Thread Tools
Old 01 January 2018, 03:11   #1
Registered User

gazj82's Avatar
Join Date: Jan 2014
Location: Cambs / UK
Posts: 340
Blitz Basic - NEWTYPES

Happy new year all!

I need some help with NEWTYPES in blitz basic.

Here is some of my code
NEWTYPE .sprite
DEFTYPE .sprite player
DEFTYPE .sprite enemy1
DEFTYPE .sprite enemy2
Now player works fine, just as expected. The trouble is I want to have two (or more) of the same enemy following the same code using a for loop. When I used to use dim'd arrays for this I could do this easily. How can I reference the right enemyX in a for loop. I guess it would be something like this.

for ene=1 to 2
enemy(ene)\x + 1
next ene
Surely there must be a way of doing this and I just don't know the syntax?
gazj82 is offline  
Old 01 January 2018, 04:39   #2
Registered User

Join Date: Dec 2013
Location: Auckland
Posts: 1,894
That looks just fine to me (except next ene is redundant though? just use next?). Do remember that arrays are zero indexed though. Here's an example (truncated) from an actual game project of mine.


Dim Players.Entity(4)
for i = 0 to 3
earok is offline  
Old 01 January 2018, 19:27   #3
Registered User

Daedalus's Avatar
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 3,559
Arrays are zero indexed, but also count the index of the amount they're DIM'd to. For example, Players.Entity(4) has 5 elements, indexed 0, 1, 2, 3 and 4.

This is not the case for arrays *within* Newtypes (e.g. Players\skill[1] will only have a [0] index), but arrays of primitives and Newtypes have n+1 members.

As for another way of doing it, there isn't really. The data you want to access is within an array, so you must provide an index. However, there is a compiler shortcut you can use: the Usepath command. This tells the compiler the default Newtype root to use, and can include variables. So, to borrow earok's example:

Dim Players.Entity(4)

Usepath Players(i)

for i = 0 to 3
Finally, the variable with the Next keyword is optional, but I make a habit of including it anyway, since it helps avoid potential bugs when you have a number of nested loops. But that's just me - I also like to use the enforced type declarations of AmiBlitz3 too
Daedalus is offline  
Old 02 January 2018, 02:26   #4
Registered User

gazj82's Avatar
Join Date: Jan 2014
Location: Cambs / UK
Posts: 340
Should have replied ages ago. Thanks Earok your post got me moving again. I did no dim'd arrays start at 0.

Thank you for your help to Deadalus
gazj82 is offline  

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
[blitz basic] How much amiga-blitz friendly is this? saimon69 Coders. Blitz Basic 104 29 November 2016 21:45
Blitz Basic vs E vs Something Else naviward Coders. General 14 28 May 2016 22:38
Blitz Basic (1) Retro1234 Coders. Blitz Basic 9 18 February 2016 18:54
Blitz basic 2 Help Havie Coders. Blitz Basic 30 08 September 2013 10:15
blitz basic petza request.Apps 11 08 April 2007 02:49

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +2. The time now is 16:00.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Page generated in 0.06240 seconds with 15 queries