Ultimate Amiga

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Question about two dimensional array.....  (Read 5908 times)

0 Members and 2 Guests are viewing this topic.

xboxisfinished

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 205
  • Generic Amiga User
    • gamemakermagazine.com
Question about two dimensional array.....
« on: October 20, 2013, 02:46:27 PM »

   Hey,

I have one question about two dimensional array. Say I have an array called MyTwoDimensionalArray and in it I have these parameters:

MyTwoDimensionalArray(31,21)

How do I store the value X1, Y1 into the two dimensional array?

I cannot do this: MyTwoDimensionalArray(0,0)=X1, MyTwoDimensionalArray(0,0)=Y1...because the computer does not know that in the two dimensional array I am storing two values one X1 in the X coordinate and Y1 in the Y coordinate of the variable MyTwoDimensionalArray...thus if I have go MyTwoDimensionalArray(0,0) it should return X1 and Y1 where X1 is stored in X=0 of MyTwoDimensionalArray and Y1 is stored in Y=0 of MyTwoDimensionalArray. Any idea how to achieve this?

Thanks in advance.
Logged

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: Question about two dimensional array.....
« Reply #1 on: October 21, 2013, 12:39:57 AM »

How about multiple 2D arrays?  One for the X1 setting and one for the Y1 setting.
Logged

xboxisfinished

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 205
  • Generic Amiga User
    • gamemakermagazine.com
Re: Question about two dimensional array.....
« Reply #2 on: October 21, 2013, 12:48:35 AM »

Yeah I suppose I could like this:

1) FirstArrayX(31)
2) FirstArrayY(31)
3) SecondArrayX(31)
4) ThirdArrayY(31)

But from my understanding...a powerful and strong programming language should give you the ability to have more than one dimensional array and be able to put values into it.

For example in Javascript you can have something like this

MyArray[5][5]

And then when I put the values into the array I get to do something like this for example

Dim values(,) As String = New String(,) {{"ant", "aunt"},
                   {"Sam", "Samantha"},
                   {"clozapine", "quetiapine"},
                   {"flomax", "volmax"},
                   {"toradol", "tramadol"}}

An example in VB.NET 2D dimensional array. If AMOS is a very low level programming language with certain essential limitations such as these...I am hoping you guys would implement these features...it is pretty much essential.
Also can AMOS do inheritance of class? For example I was noticing in AMOS with 512 KB chip RAM I have a limit to how much buffer of text I can put...that means I am very much limited and restricted eventually to the amount of code I can put. What if I want to write a very complex and big game...with say 1, 000 million of code...which I know...lines of code does not determine quality of game and good programming practice of efficiency in coding style and lines of code does not determine the quality of the program. I know all of that. Someone could write a game with 200 lines of code that is very interesting and make money out of it...I understand.

However, assume in my situation with my method of coding (each have their own way of writing programs all together) I might say require to write 10,000 lines of code that someone could write in 2000  for example..but it could happen and I am one of these guys...I may not be able to do that...and I do not feel good inside me to keep asking people to change my code...I do not feel it is mine anymore. So assume with the limitation of buffer text I cannot write that 10,000 lines of code and I am stuck with writing 5,000 lines of code...not even that....2,500 lines of code is all I can do. Can I then inherit other classes and write my program in chunks of 2,500 per file and combine them in a main program file that inherits the rest of the classes and uses the functions and procedures of those classes? I am just wondering.
Logged

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: Question about two dimensional array.....
« Reply #3 on: October 21, 2013, 01:11:30 AM »

AmosPro is not object-oriented.  The Mattathias BASIC project by Sidewinder and myself attempted to add that to AmosPro.  It failed miserably in that regard.

If you want OOP, use a different language.  AmigaE is like an object-oriented BASIC with a few exceptions.

EDIT

Also, 2D arrays are allowed in AmosPro but custom structure types are not.
Logged

xboxisfinished

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 205
  • Generic Amiga User
    • gamemakermagazine.com
Re: Question about two dimensional array.....
« Reply #4 on: October 21, 2013, 01:14:46 AM »

Can't you implement certain object oriented language feature into AMOS such as class? I mean I will use it for simple game development and fast arcade game developments and such....and to have easy and fast results...but I will use AmiBlitz 3 for OOP and more complex projects in the future and keep using AMOS as a game making tool...like adventure construction set with understanding there are limitations to it. You said 2D array is accepted but I still not know how to add values into the (X,Y) point of the array.  My game is almost done but is blocked with this problem. If you are saying adding values into X,Y is not possible in the same way as I was wanting it...and I am forced to have separate arrays for different value..just tell me that now so I can resume game development immediately.
« Last Edit: October 21, 2013, 01:17:24 AM by xboxisfinished »
Logged

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: Question about two dimensional array.....
« Reply #5 on: October 21, 2013, 01:37:21 AM »

As I tried to tell you before, the only 3 types supported by arrays are integers, real (floating point), and strings.  There are no classes.  There are no structures.  (The difference between classes and structures are that classes support inheritance.)  BlitzBasic supports structures but not OOP and has a generally better compiler technology.

You can't put more than one value in an array index without going in and doing it manually in banks like I tried to show you before.

Dim X1(31,24), Y1(31,24)

That is legal in AmosPro.

Dim MyArray(31,24) as myStructureType

That is not ever supported in AmosPro.
Logged

xboxisfinished

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 205
  • Generic Amiga User
    • gamemakermagazine.com
Re: Question about two dimensional array.....
« Reply #6 on: October 21, 2013, 02:30:33 AM »

OK now I understand completely what I am dealing with here all together. It seems I still need to grasp the bank system all together. I am going to paste the code here with my correction and what I will do with it in my own...so you can see me on top of my shoulder and tell me where I went wrong or tell me you are doing it right.

So Board is the declared value I have at the beginning of the program, boardsteps is set to five and is set as global variable at the top of my program. BoardX is set 0 and BoardY is 1 and it is also a global value at the beginning of the program.  This value here  ITEMLOC= Fn BOARDARRAY(X,Y,0,15+X) I have fixed it and made it like this instead ITEMLOC= Fn BOARDARRAY(X,Y,0,15). However, offset will always and always be zero....is that wrong? If so..how do I know what offset it will be in? This one here  you said it is wrong If Peek(ITEMLOC+10)=0 it should really be If Peek(ITEMLOC+0)=0 or 1, or 2, or 3, because my understanding that is actually the index of the array as say Array(0) and Array(1) and so on. If that is what you are saying is true...why do I need Fn BOARDARRAY(X,Y....then? Aren't these X,Y the same as Array(X,Y)? Should these be the ones that change in value or what you are saying that ITEMLOC+0 should always be zero?

HA! So I have proved that I did not really understand how this works all together...but hopefully it will stick in my hand and I will become professional on this!

Code: [Select]
Procedure SETBOARDARRAY[X1INIT,Y1INIT,X2INIT,Y2INIT]
   Shared BOARDSTEPS,BOARDX,BOARDY,BOARD
   For Y=0 To 21
      For X=0 To 32
         Def Fn BOARDARRAY(X,Y,OFFSET,BANKNUM)=BOARDHEADER+OFFSET+((X+Y*(Peek(Start(BANKNUM)+BOARDX))*BOARDSTEPS))
         ITEMLOC= Fn BOARDARRAY(X,Y,0,15)
         If Peek(ITEMLOC+10)=0
            Doke ITEMLOC+X1,X1INIT
            Doke ITEMLOC+Y1,Y1INIT
            Doke ITEMLOC+X2,X2INIT
            Doke ITEMLOC+Y2,Y2INIT
            Locate 20,20 : Print Peek( Fn BOARDARRAY(0,0,OFFSET,15+X))
            Wait 30
            Locate 20,20 : Print "               "
            Goto QUIT
         End If
      Next X
  Next Y
QUIT:
End Proc
Logged

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: Question about two dimensional array.....
« Reply #7 on: October 21, 2013, 10:26:36 PM »

I'll respond in the other thread to keep things on-topic.
Logged

Atheist

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 3
  • Generic Amiga User
Re: Question about two dimensional array.....
« Reply #8 on: September 13, 2017, 01:27:06 PM »

Hey,

I have one question about two dimensional array. Say I have an array called MyTwoDimensionalArray and in it I have these parameters:

MyTwoDimensionalArray(31,21)

How do I store the value X1, Y1 into the two dimensional array?

I cannot do this: MyTwoDimensionalArray(0,0)=X1, MyTwoDimensionalArray(0,0)=Y1...because the computer does not know that in the two dimensional array I am storing two values one X1 in the X coordinate and Y1 in the Y coordinate of the variable MyTwoDimensionalArray...thus if I have go MyTwoDimensionalArray(0,0) it should return X1 and Y1 where X1 is stored in X=0 of MyTwoDimensionalArray and Y1 is stored in Y=0 of MyTwoDimensionalArray. Any idea how to achieve this?

Thanks in advance.
Hi xboxisfinished,

I LOVE arrays!

Your array "MyTwoDimensionalArray(31,21)" makes a grid of 32*22 elements = 704 variables can be stored. I had to add an extra number because Array numbering starts at "0".

There is a MyTwoDimensionalArray(0,y) and MyTwoDimensionalArray(x,0) in every array line.

I think what you want is
Code: [Select]
Dim MyTwoDimensionalArray(31,1)
For E=0 to 31
 Read X,Y
 MyTwoDimensionalArray(E,0)=X
 MyTwoDimensionalArray(E,1)=Y
Next E
I chose "E" for "element".

Change the "read" statement to
 Read MyTwoDimensionalArray(E,0),MyTwoDimensionalArray(E,1)
to maximise speed.

Code: [Select]
For E=0 to 31
 Plot MyTwoDimensionalArray(E,0),MyTwoDimensionalArray(E,1)
Next E
Would put dots all over the screen.

Code: [Select]
For E=0 to 31
 Text MyTwoDimensionalArray(E,0),MyTwoDimensionalArray(E,1),"Hello world!"
Next E
Would print text all over the screen.

Code: [Select]
Dim MyTwoDimensionalArray(31,3)
For E=0 to 31
 Read MyTwoDimensionalArray(E,0),MyTwoDimensionalArray(E,1),MyTwoDimensionalArray(E,2),MyTwoDimensionalArray(E,3)
 Draw MyTwoDimensionalArray(E,0),MyTwoDimensionalArray(E,1) to MyTwoDimensionalArray(E,2),MyTwoDimensionalArray(E,3)
Next E

Will give you the start and end points of lines.

I was so sure that there was a way to make arrays start at "1" instead of "0" but can't find that command.

Hope that helps.... even though it's been a few years.

(I joined this messageboard today.)
Logged

Atheist

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 3
  • Generic Amiga User
Re: Question about two dimensional array.....
« Reply #9 on: September 13, 2017, 01:46:45 PM »

For example I was noticing in AMOS with 512 KB chip RAM I have a limit to how much buffer of text I can put...that means I am very much limited and restricted eventually to the amount of code I can put.
Hi xboxisfinished,

Okay, you've probably resolved this by now, but I'm replying anyway.

While I don't understand most of the terminology that SamuraiCrow and you are using, you CAN get more buffer space.
Set Buffer 100
Will give you 100K of space for variables. It also allows you to increase the size of your program.

What if I want to write a very complex and big game...with say 1, 000 million of code...which I know...lines of code does not determine quality of game and good programming practice of efficiency in coding style and lines of code does not determine the quality of the program. I know all of that. Someone could write a game with 200 lines of code that is very interesting and make money out of it...I understand.

I've written a single program that is ~435,000 bytes when saved onto a floppy disk. And that wasn't in ASCII format. Mind you, you do have to have more RAM than that, in the computer you are using.
Logged
Pages: [1]   Go Up
 

TinyPortal 2.2.2 © 2005-2022