01 January 2018, 02:11 | #1 |
Registered User
Join Date: Jan 2014
Location: Cambs / UK
Posts: 356
|
Blitz Basic - NEWTYPES
Happy new year all!
I need some help with NEWTYPES in blitz basic. Here is some of my code Code:
.variables DEFTYPE .w NEWTYPE .sprite x.w y.w oldx.w oldy.w frame.w speed.w direction.w olddirection.w End NEWTYPE DEFTYPE .sprite player DEFTYPE .sprite enemy1 DEFTYPE .sprite enemy2 Code:
for ene=1 to 2 enemy(ene)\x + 1 next ene |
01 January 2018, 03:39 | #2 |
Registered User
Join Date: Dec 2013
Location: Auckland
Posts: 3,548
|
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.
NEWTYPE .Entity ID.b X.q Y.q End NEWTYPE Dim Players.Entity(4) for i = 0 to 3 Players(i)\ID=i Players(i)\Y=300 next |
01 January 2018, 18:27 | #3 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,381
|
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: Code:
Dim Players.Entity(4) Usepath Players(i) for i = 0 to 3 \ID=i \Y=300 next |
02 January 2018, 01:26 | #4 |
Registered User
Join Date: Jan 2014
Location: Cambs / UK
Posts: 356
|
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 |
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 | 105 | 21 April 2022 19:45 |
Blitz Basic vs E vs Something Else | naviward | Coders. General | 14 | 28 May 2016 21:38 |
Blitz Basic (1) | Retro1234 | Coders. Blitz Basic | 9 | 18 February 2016 17:54 |
Blitz basic 2 Help | Havie | Coders. Blitz Basic | 30 | 08 September 2013 09:15 |
blitz basic | petza | request.Apps | 11 | 08 April 2007 01:49 |
|
|