Ultimate Amiga
Network Boards => AMOS Language Discussion => AMOS Factory => AMOS Professional Forum => Topic started by: xboxisfinished on October 10, 2013, 11:34:56 PM
-
I have being reading the manual of AMOS about bank and it seems interesting. My favourite part is that I can place variables only on the FAST ram and anything to do with graphics, audio must go on the CHIP side of things. However as I read through it I am confused in how to use it in my project?
For example this is what I want to do....
NewType boardsteps
int X1
int Y1
int X2
int Y2
boolean twolinesformed
End NewType
Deftype.boardsteps Board(32,21)
Then for example I can do this:
Board(0,0)\X1=12, Board(0,0)\Y1=14,
Board(0,0)\X2=114, Board(0,0)\Y2=13, Board(0,0)\twolinesformed=false
Why do I need to do that? Simple, in the board there are 30 dots from left to right and 20 dots from top to bottom giving a total of 600 dots in the entire board.....so if I have something like this:
O1 O2 O3
O4 O5 O6
O7 O8 O9
If the user clicks on O1 it stores in board(0,0)\X1=14, board(0,0)\Y1=4 and then a red dot is plotted on O1. Now the user have another round to plot another dot..so he selects on O2.
There the board(0,0)\X2=18, board(0,0)\Y2=4 is stored...then the game checks to see if board(0,0) and board(0,0) X1, Y1, X2, Y2 plot are in the valid location...if they are...then it stores the X2 and Y2 in board(0,0) accordingly. After that..it plots the red dot on the second dot selected...then it forms a red line between the first do and the second dot. Then in that board(0,0)\twolinesformed=true.
Now turn 2 starts and it is the second player...here the player selects again another dot on the board and instead of being board(0,0), the game checks to see if board(0,0) is used..if it is..it increments the second index board(1,0) if that is used it increments again and becomes board(2,0) if that is not used then it adds the values there and repeats.
Now this is how I want to achieve it..the question comes in how do I do that with banks and array and how do I declare an array with type bank like I showed you before and how do I store all that in FAST RAM only?
Thanks in advance.
-
How big of an int do you need to use? If it's between 0 and 255 at all times, an unsigned byte will be sufficient. A boolean should be a byte also. That being the case, I'll make a tile-map with a header that stores the size of the array and the array itself.
rem assumes int is a byte and boolean is a byte
rem size of boardsteps is 4*int+1=5 bytes
boardsteps=5
rem offsets within the 5 byte space are as follows
x1=0
y1=1
x2=2
y2=3
twolinesformed=4
rem now for the header to store the size of the array
boardheader=2
rem offsets within the header
boardx=0
boardy=1
rem now to allocate the board
board=boardheader+(32*21*boardsteps)
Reserve As Work 15,board
poke start(15)+boardx,32
poke start(15)+boardy,21
def fn boardarray(x,y,offset,banknum) boardheader+offset+((x+y*(peek(start(banknum)+boardx))*boardsteps)
rem here's how to store something in twolinesformed with x=0 and y=3
poke fn boardarray(0,3,twolinesformed,15), TRUE
rem you read it back with
print peek (fn boardarray(0,3,twolinesformed,15)
rem if you want to do a value range check for the array here it is
def fn rngchk(x,y,offset, banknum) (x<peek(start(banknum)+boardx)) and (y<peek(start(banknum)+boardy)) and (offset<boardsteps)
if fn rngchk(0,3,twolinesformed,15) then poke fn boardarray(0,3,twolinesformed,15),FALSE
-
If you need int to be 16 bits for values between 0 and 65535 it gets trickier but not by much. You Deek and Doke the int offsets and Peek and Poke the boolean normally. Also, the size of the record must be even to insure that all of the ints fall on even addresses.
rem assumes int is a word and boolean is a byte
rem size of boardsteps is 4*int+1=9 bytes
rem since 9 is not even we add a pad byte that will remain unused.
boardsteps=10
rem offsets within the 10 byte space are as follows
x1=0
y1=2
x2=4
y2=6
twolinesformed=8
rem now for the header to store the size of the array
boardheader=4
rem offsets within the header
boardx=0
boardy=2
rem now to allocate the board
board=boardheader+(32*21*boardsteps)
Reserve As Work 15,board
Doke start(15)+boardx,32
Doke start(15)+boardy,21
def fn boardarray(x,y,offset,banknum) boardheader+offset+((x+y*(Deek(start(banknum)+boardx))*boardsteps)
rem here's how to store something in twolinesformed with x=0 and y=3
poke fn boardarray(0,3,twolinesformed,15), TRUE
rem you read it back with
print peek (fn boardarray(0,3,twolinesformed,15)
rem if you want to do a value range check for the array here it is
def fn rngchk(x,y,offset, banknum) (x<Deek(start(banknum)+boardx)) and (y<Deek(start(banknum)+boardy)) and (offset<boardsteps-1)
if fn rngchk(0,3,twolinesformed,15) then poke fn boardarray(0,3,twolinesformed,15),FALSE
rem to read x1 you do this
print Deek(fn boardarray(0,3,x1,15)
-
How big of an int do you need to use? If it's between 0 and 255 at all times, an unsigned byte will be sufficient. A boolean should be a byte also. That being the case, I'll make a tile-map with a header that stores the size of the array and the array itself.
rem assumes int is a byte and boolean is a byte
rem size of boardsteps is 4*int+1=5 bytes
boardsteps=5
rem offsets within the 5 byte space are as follows
x1=0
y1=1
x2=2
y2=3
twolinesformed=4
rem now for the header to store the size of the array
boardheader=2
rem offsets within the header
boardx=0
boardy=1
rem now to allocate the board
board=boardheader+(32*21*boardsteps)
Reserve As Work 15,board
poke start(15)+boardx,32
poke start(15)+boardy,21
def fn boardarray(x,y,offset,banknum) boardheader+offset+((x+y*(peek(start(banknum)+boardx))*boardsteps)
rem here's how to store something in twolinesformed with x=0 and y=3
poke fn boardarray(0,3,twolinesformed,15), TRUE
rem you read it back with
print peek (fn boardarray(0,3,twolinesformed,15)
rem if you want to do a value range check for the array here it is
def fn rngchk(x,y,offset, banknum) (x<peek(start(banknum)+boardx)) and (y<peek(start(banknum)+boardy)) and (offset<boardsteps)
if fn rngchk(0,3,twolinesformed,15) then poke fn boardarray(0,3,twolinesformed,15),FALSE
Thank you so much for your reply :) I just have couple of questions I need to ask as a learning purpose and understand how it works all together. If I do not understand it...I will always get frustrated, I will always ask people to solve it for me...and I will not feel good and feel like a junior programmer all the time. But ones you teach me how it works....ones I understand it the same way I understand how I am typing these words....I will be able to do it in my own...and I will feel good about myself....not be that annoying monkey in your backs...and at the same time I will have the confident to make better and more complex games that I have always dreamed to do...plus have fun with my code ;D.
rem assumes int is a byte and boolean is a byte
rem size of boardsteps is 4*int+1=5 bytes
boardsteps=5
Is boardsteps the same as the one I have done at the beginning of the post NewType.boardsteps? Is the reason you put five because I have five variables which are the following: int X1,int Y1,int X2,int Y2,boolean twolinesformed?
rem offsets within the 5 byte space are as follows
x1=0
y1=1
x2=2
y2=3
I assume the x1,y1,x2,y2 is obtained from the
NewType.boardsteps
x1
y1
x2
y2
end newtype
Am I correct so far?
Here in this line of code you said twolinesformed=8. Why 8? Why not True of False?
rem now for the header to store the size of the array
boardheader=4
The above code I do not understand. Why you made a variable boardheader and why you set it to 4 and not 2 or 3 or any number, why 4? You said in the commentary that it store the size of the array...but the array I want is board(32,21) with type boardsteps.
Now you lost me in the below code O_O:
rem offsets within the header
boardx=0
boardy=2
Why do we need header and why do we need offset?
Now come to the most complicated part of the code
rem now to allocate the board
board=boardheader+(32*21*boardsteps)
Reserve As Work 15,board
poke start(15)+boardx,32
poke start(15)+boardy,21
OK you declared a variable called board but what is that formula you made above there where boardheader+(32*21*boardsteps) I do not understand how this work. So boardheader equals to 4 and what is 32 * 21 * boardsteps (where boardsteps equal to 5). I do not understand all how this works at all...and how is that equivalent to board(30, 31).
Now here you have the code Reserve As Work 15, board can I have it as Reserve As Fast 15, board...second of all what is 15 and why you chose board right after 15.?
poke start(15)+boardx,32
poke start(15)+boardy,21
Is that above the same as arrayvariable(32,21)?
def fn boardarray(x,y,offset,banknum) boardheader+offset+((x+y*(peek(start(banknum)+boardx))*boardsteps)
rem here's how to store something in twolinesformed with x=0 and y=3
poke fn boardarray(0,3,twolinesformed,15), TRUE
rem you read it back with
print peek (fn boardarray(0,3,twolinesformed,15)
rem if you want to do a value range check for the array here it is
def fn rngchk(x,y,offset, banknum) (x<peek(start(banknum)+boardx)) and (y<peek(start(banknum)+boardy)) and (offset<boardsteps)
if fn rngchk(0,3,twolinesformed,15) then poke fn boardarray(0,3,twolinesformed,15),FALSE
Ok the above code I do understand a single bit of it....can you explain the things above in terms of language I understand...thanks?
-
How big of an int do you need to use? If it's between 0 and 255 at all times, an unsigned byte will be sufficient. A boolean should be a byte also. That being the case, I'll make a tile-map with a header that stores the size of the array and the array itself.
rem assumes int is a byte and boolean is a byte
rem size of boardsteps is 4*int+1=5 bytes
boardsteps=5
rem offsets within the 5 byte space are as follows
x1=0
y1=1
x2=2
y2=3
twolinesformed=4
rem now for the header to store the size of the array
boardheader=2
rem offsets within the header
boardx=0
boardy=1
rem now to allocate the board
board=boardheader+(32*21*boardsteps)
Reserve As Work 15,board
poke start(15)+boardx,32
poke start(15)+boardy,21
def fn boardarray(x,y,offset,banknum) boardheader+offset+((x+y*(peek(start(banknum)+boardx))*boardsteps)
rem here's how to store something in twolinesformed with x=0 and y=3
poke fn boardarray(0,3,twolinesformed,15), TRUE
rem you read it back with
print peek (fn boardarray(0,3,twolinesformed,15)
rem if you want to do a value range check for the array here it is
def fn rngchk(x,y,offset, banknum) (x<peek(start(banknum)+boardx)) and (y<peek(start(banknum)+boardy)) and (offset<boardsteps)
if fn rngchk(0,3,twolinesformed,15) then poke fn boardarray(0,3,twolinesformed,15),FALSE
Thank you so much for your reply :) I just have couple of questions I need to ask as a learning purpose and understand how it works all together. If I do not understand it...I will always get frustrated, I will always ask people to solve it for me...and I will not feel good and feel like a junior programmer all the time. But ones you teach me how it works....ones I understand it the same way I understand how I am typing these words....I will be able to do it in my own...and I will feel good about myself....not be that annoying monkey in your backs...and at the same time I will have the confident to make better and more complex games that I have always dreamed to do...plus have fun with my code ;D.
No problem!
rem assumes int is a byte and boolean is a byte
rem size of boardsteps is 4*int+1=5 bytes
boardsteps=5
Is boardsteps the same as the one I have done at the beginning of the post NewType.boardsteps? Is the reason you put five because I have five variables which are the following: int X1,int Y1,int X2,int Y2,boolean twolinesformed?
In my example, boardsteps is the size of of the boardsteps type in bytes.
rem offsets within the 5 byte space are as follows
x1=0
y1=1
x2=2
y2=3
I assume the x1,y1,x2,y2 is obtained from the
NewType.boardsteps
x1
y1
x2
y2
end newtype
Am I correct so far?
Yes.
Here in this line of code you said twolinesformed=8. Why 8? Why not True of False?
It's an offset. It's not a value, it's a location within the structure type.
rem now for the header to store the size of the array
boardheader=4
The above code I do not understand. Why you made a variable boardheader and why you set it to 4 and not 2 or 3 or any number, why 4? You said in the commentary that it store the size of the array...but the array I want is board(32,21) with type boardsteps.
Now you lost me in the below code O_O:
rem offsets within the header
boardx=0
boardy=2
Why do we need header and why do we need offset?
The header is used to store the dimensions of the array. It is used by the other formulas.
Now come to the most complicated part of the code
rem now to allocate the board
board=boardheader+(32*21*boardsteps)
Reserve As Work 15,board
poke start(15)+boardx,32
poke start(15)+boardy,21
OK you declared a variable called board but what is that formula you made above there where boardheader+(32*21*boardsteps) I do not understand how this work. So boardheader equals to 4 and what is 32 * 21 * boardsteps (where boardsteps equal to 5). I do not understand all how this works at all...and how is that equivalent to board(30, 31).
Start(15)+boardheader marks the start of the actual array. Also, I gave two examples and you're mixing up between them. In the first example boardheader was only 2 bytes of storage. This is dimensioning an array manually in memory. Since in the second example, I used word-sized dimensions the array can grow bigger. Generally I avoid using longword-sized offsets unless they are needed because it slows the system down. This is how a regular array would work.
Now here you have the code Reserve As Work 15, board can I have it as Reserve As Fast 15, board...second of all what is 15 and why you chose board right after 15.?
poke start(15)+boardx,32
poke start(15)+boardy,21
Is that above the same as arrayvariable(32,21)?
That is storing the dimensions of the array in the header. Yes.
def fn boardarray(x,y,offset,banknum) boardheader+offset+((x+y*(peek(start(banknum)+boardx))*boardsteps)
rem here's how to store something in twolinesformed with x=0 and y=3
poke fn boardarray(0,3,twolinesformed,15), TRUE
rem you read it back with
print peek (fn boardarray(0,3,twolinesformed,15)
rem if you want to do a value range check for the array here it is
def fn rngchk(x,y,offset, banknum) (x<peek(start(banknum)+boardx)) and (y<peek(start(banknum)+boardy)) and (offset<boardsteps)
if fn rngchk(0,3,twolinesformed,15) then poke fn boardarray(0,3,twolinesformed,15),FALSE
Ok the above code I do understand a single bit of it....can you explain the things above in terms of language I understand...thanks?
The def fn command defines a function with a return value of type integer. It's essentially like a one-line procedure with a return value. The formulas contained in them are the way to do an array lookup when doing things manually.
If you use arrays in your code, the compiler or interpreter generates all of this for you. If you do banks of memory in Amos you have to do in manually. Sometimes this is desirable since you can use integers that are smaller than 4 bytes each, as I have done in these examples. On an Amiga 500 (or any 16-bit Amiga) the smaller 2-byte integers access at twice the speed of 4-byte integers in addition to taking less memory.
Peek reads a byte from memory. Poke writes a byte to memory. Start(15) is the address of bank 15's contents in memory. Deek reads a 2-byte word from memory if it is properly on an even address (otherwise it causes a bus error). Likewise Doke writes a word of memory to an even address.
Once you read the answers to the earlier questions, it should make more sense.
-
OK the first thing you said that twolinesformed=8 is an actual location it is an offset and not a value. My question why would i need to know the location of twolinesformed if I am going to be using the Array(X,Y) with the stype boardsteps. Do I still need to know each variable, x1,y1,x2,y2 and twolinesformed their offset location before placing values in them? How then the concept of array works if I am manually having to locate their value in memory?
The second part where I asked you about boardheader=4 you said that is to store the dminseions of the array...but from the looks of it I am using single array with size 4...so this I need to ignore then completely and just simply focus on the two dimension array with size more than 4. Am I correct so far?
But...maybe I am wrong completely maybe i still need boardheader because you are using it to store the value of board. But why 4? Is 4 enough for what I am using? What if I went larger would they ruin the whole thing?
In this code down below:
rem now to allocate the board
board=boardheader+(32*21*boardsteps)
Reserve As Work 15,board
poke start(15)+boardx,32
poke start(15)+boardy,21
You said Start(15)+boardheader marks the start of the actual array...why you choose 15? Why not 0 or 12 or 3 or 6? Does that mean all my arrays they must start at 15?
Now here is the thing that I am little confused...you said boardx and boardy...am I taking it that these size will change based on the mouse location or the cursor location in the board or how exactly are these values changed?
Can boardx=210, boardy=34? Does that mean if the plotted dot on the board is plotted on 210, 34 that these values will actually be stored in boardx and boardy and the size of the array is array(32,21) is that how it work? But what about X2 and Y2...where does that go?
You said poke start(15)+boardx, 32 and poke start(15)+boardy,21 is the storing of the dimensions of the array in the header...you confirmed that with a yes. That is good so far....
So how does this work
for y=0 to 21
for x=0 to 32
if boardarray(x,y)=0
board(x,y)\x1=x1:board(x,y)\y1=y1:board(x,y)\x2=x2:board(x,y)\y2=y2
' do the necessary flags to quit the entire loop all together
end if
next x
next y
With what you did up in terms of poke start(15)+boardx, 32 and poke start(15)+boardy, 21, I do not see the x1,y1,x2,y2 in the equation and most importantly I do not see or know what is suppose to increment boardx, and boardy with and by how much and why?
You said this "If you use arrays in your code, the compiler or interpreter generates all of this for you. If you do banks of memory in Amos you have to do in manually. Sometimes this is desirable since you can use integers that are smaller than 4 bytes each, as I have done in these examples. On an Amiga 500 (or any 16-bit Amiga) the smaller 2-byte integers access at twice the speed of 4-byte integers in addition to taking less memory."
What if I do not want to have the "Advanced" version of array...and maybe to some..they need full control of everything and perhaps they can use it to optimize their code and execution to be a junior level like me and who is new in AMOS will find this a bit of an advanced topic. He wants to learn the scope of programming in AMOS and what to feel happy he have released his first Amiga game so he can move on to the next project...now maybe I should learn this in the future because maybe my future projects demand that I go through this approach...now essentially my question to you is...do I have to do it this way as you said below:
def fn boardarray(x,y,offset,banknum) boardheader+offset+((x+y*(peek(start(banknum)+boardx))*boardsteps)
and ther eis no other option behind it? If what you are saying is true...then teach me the above how it works all together, the x,y, offset, banknum with boardheader+offset+x+y, etc...pretend I am a student coming to first year class university. I have no idea what so ever in the above code how it works and function and why you did it this way and why you inclided banknum and why you also included boardsteps and how are these values boardheader, offset, x,y, boardx and boardsteps changes value in during game and why they needed to be changed?
Here is my question if I want to take this code here
for y=0 to 21
for x=0 to 32
if boardarray(x,y)=0
board(x,y)\x1=x1:board(x,y)\y1=y1:board(x,y)\x2=x2:board(x,y)\y2=y2
' do the necessary flags to quit the entire loop all together
end if
next x
next y
using the boardstep how do I go about doing that with bank? Forgive me if I sound a little frustrated, it just I am not understanding how this works...and no course in university is going to teach me this and I have no intention of going through the beuracracy of taking a course in college and spending 1000 dollars for four month to teach me this and they are not going to teach me this...they are going to teach me .net and visual studio and html5...so..and no book here in AMOS is going to teach me either...I need someone here in the community to explain this to me...I promise ones you explain it to me (slowly) and I get it...it will stick in my brain and I can zoom clearing without any problem...I just need to understand what you are trying to say with your code.
-
OK the first thing you said that twolinesformed=8 is an actual location it is an offset and not a value. My question why would i need to know the location of twolinesformed if I am going to be using the Array(X,Y) with the stype boardsteps. Do I still need to know each variable, x1,y1,x2,y2 and twolinesformed their offset location before placing values in them? How then the concept of array works if I am manually having to locate their value in memory?
There are no custom structure types in AmosPro. That's why you have to do it manually. Also, if you know that the values of x, y, and offset are in range, you can skip the range check and it will run faster that an array. Arrays in AmosPro always use one of the following 3 types: integer, floating point, or string. An array access always does a range check whether you ask it to or not and the compiler isn't smart enough to realize that constants can be determined to be in or out of range without having to do a runtime check.
The second part where I asked you about boardheader=4 you said that is to store the dminseions of the array...but from the looks of it I am using single array with size 4...so this I need to ignore then completely and just simply focus on the two dimension array with size more than 4. Am I correct so far?
The header stores 2 integers at 2 bytes each. 2*2=4. If you want more dimensions or metadata or other information to be stored once then the header is definitely the place for it.
Also there is one more advantage of using a bank over using an array: You can load or save the bank to or from disk without much effort.
But...maybe I am wrong completely maybe i still need boardheader because you are using it to store the value of board. But why 4? Is 4 enough for what I am using? What if I went larger would they ruin the whole thing?
In this code down below:
rem now to allocate the board
board=boardheader+(32*21*boardsteps)
Reserve As Work 15,board
poke start(15)+boardx,32
poke start(15)+boardy,21
You said Start(15)+boardheader marks the start of the actual array...why you choose 15? Why not 0 or 12 or 3 or 6? Does that mean all my arrays they must start at 15?
Wrong. It means you are using bank number 15. It is the last bank supported in Amos the Creator and although AmosPro can use higher bank numbers, the lowest bank numbers are normally reserved for images, icons, music, sound effects and other data structures.
Now here is the thing that I am little confused...you said boardx and boardy...am I taking it that these size will change based on the mouse location or the cursor location in the board or how exactly are these values changed?
They are constant offsets within the bank. The values they contain will change based on the size of the map. The header itself just contains array dimensions at this point but can be expanded to store additional data as well.
Can boardx=210, boardy=34? Does that mean if the plotted dot on the board is plotted on 210, 34 that these values will actually be stored in boardx and boardy and the size of the array is array(32,21) is that how it work? But what about X2 and Y2...where does that go?
If there were a way to make boardx and boardy constants that never change I would have done so. The only reason I kept them as variables is to avoid having to explain the structure offset functions of AmosPro which aren't much better than just naming offsets like I did here.
You said poke start(15)+boardx, 32 and poke start(15)+boardy,21 is the storing of the dimensions of the array in the header...you confirmed that with a yes. That is good so far....
So how does this work
for y=0 to 21
for x=0 to 32
if boardarray(x,y)=0
board(x,y)\x1=x1:board(x,y)\y1=y1:board(x,y)\x2=x2:board(x,y)\y2=y2
' do the necessary flags to quit the entire loop all together
end if
next x
next y
With what you did up in terms of poke start(15)+boardx, 32 and poke start(15)+boardy, 21, I do not see the x1,y1,x2,y2 in the equation and most importantly I do not see or know what is suppose to increment boardx, and boardy with and by how much and why?
NEVER change a constant. It isn't supposed to vary.
You said this "If you use arrays in your code, the compiler or interpreter generates all of this for you. If you do banks of memory in Amos you have to do in manually. Sometimes this is desirable since you can use integers that are smaller than 4 bytes each, as I have done in these examples. On an Amiga 500 (or any 16-bit Amiga) the smaller 2-byte integers access at twice the speed of 4-byte integers in addition to taking less memory."
What if I do not want to have the "Advanced" version of array...and maybe to some..they need full control of everything and perhaps they can use it to optimize their code and execution to be a junior level like me and who is new in AMOS will find this a bit of an advanced topic. He wants to learn the scope of programming in AMOS and what to feel happy he have released his first Amiga game so he can move on to the next project...now maybe I should learn this in the future because maybe my future projects demand that I go through this approach...now essentially my question to you is...do I have to do it this way as you said below:
def fn boardarray(x,y,offset,banknum) boardheader+offset+((x+y*(peek(start(banknum)+boardx))*boardsteps)
and ther eis no other option behind it? If what you are saying is true...then teach me the above how it works all together, the x,y, offset, banknum with boardheader+offset+x+y, etc...pretend I am a student coming to first year class university. I have no idea what so ever in the above code how it works and function and why you did it this way and why you inclided banknum and why you also included boardsteps and how are these values boardheader, offset, x,y, boardx and boardsteps changes value in during game and why they needed to be changed?
The reason I named the constants is so that they can be set once in the code and used many times. They aren't intended to be treated as variables.
Here is my question if I want to take this code here
for y=0 to 21
for x=0 to 32
if boardarray(x,y)=0
board(x,y)\x1=x1:board(x,y)\y1=y1:board(x,y)\x2=x2:board(x,y)\y2=y2
' do the necessary flags to quit the entire loop all together
end if
next x
next y
using the boardstep how do I go about doing that with bank?
for y=0 to 21
for x=0 to 32
if peek(fn board(x,y,value,15))=0
doke fn board(x,y,x1,15),x1init
doke fn board(x,y,y1,15),y1init
doke fn board(x,y,x2,15),x2init
doke fn board(x,y,y2,15),y2init
' do the necessary flags to quit the entire loop all together
end if
next x
next y
Note: I had to change the variable names to be different from the offset names so they wouldn't conflict so I added the word "init" to them. Also, since we don't have an actual value stored in the custom type, you'd have to add the following to the offsets within the boardsteps definition:
value=9
This uses up the pad byte that was added into the offset values so now all 10 bytes are used in the custom type.
Forgive me if I sound a little frustrated, it just I am not understanding how this works...and no course in university is going to teach me this and I have no intention of going through the beuracracy of taking a course in college and spending 1000 dollars for four month to teach me this and they are not going to teach me this...they are going to teach me .net and visual studio and html5...so..and no book here in AMOS is going to teach me either...I need someone here in the community to explain this to me...I promise ones you explain it to me (slowly) and I get it...it will stick in my brain and I can zoom clearing without any problem...I just need to understand what you are trying to say with your code.
I could teach you .NET too. But here's the clincher: .NET uses object oriented programming. You can reuse code and define accessors to get and set values. The advantage to defining an interface to the code in an OOP fashion is reusability. It slows things down though. Arrays that do range checks are easy but slow. Directly accessing memory is dangerous but fast. Also, Banks in AmosPro make storage and retrieval of boards from disk to be easier.
I forgot a set of grouping symbols in the example code:
board=boardheader+(32*(21*boardsteps))
In this case 32 is the x dimension of the manual array. 21 is the y dimension.
-
Thank you so much!! :D :D Now I understand what you are trying say...that explains some of the confusions I had earlier.
Just one question and I am done for sure...
if peek(fn board(x,y,value,15))=0
the word value there in the peek statement....what is that value? Is it changeable and what value suppose to be there? Thanks in advance.
-
If you look below the example code it is an offset within the structure and represents the constant value 9, which is the last of the 10 bytes of structure. In the earlier example it was used merely as a pad byte.
-
Now that you understand how it works, I'll show you an optimization that can make your structure array accesses much MUCH faster!
for y=0 to 21
for x=0 to 32
if peek(fn board(x,y,value,15))=0
doke fn board(x,y,x1,15),x1init
doke fn board(x,y,y1,15),y1init
doke fn board(x,y,x2,15),x2init
doke fn board(x,y,y2,15),y2init
' do the necessary flags to quit the entire loop all together
end if
next x
next y
becomes
for y=0 to 21
for x=0 to 32
itemloc=fn board(x,y,0,15)
if peek(itemloc+value)=0
doke itemloc+x1,x1init
doke itemloc+y1,y1init
doke itemloc+x2,x2init
doke itemloc+y2,y2init
' do the necessary flags to quit the entire loop all together
end if
next x
next y
Do you see how it is much faster to calculate the array index only once and access the members of the structure based on that pointer address? It's optimizations like this that C programmers use all the time!
-
I implemented the code but it is not working at all! The results are always zero! I am going to post the code here as an attachment
-
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+X)
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
Ummm... why are you trying to use multiple banks? Each bank should hold a different board.
Also, when I set up the peek to look at ITEMLOC+9 I was assuming you'd initialize that as your character instead of the other array. If you want to use the other array, just revert the bit about peeking itemloc+9 and use the array lookup you were using before.
Lastly, ITEMLOC+10 is the high byte of X1 in the next higher element of the array. Maybe I was wrong to tell you to disable the range checking. If you had an array of 10 elements and you asked for the one numbered 10 it would give you an array bounds out of range error. Array indexes and offsets start at 0 and work their way up to N-1 where N is the dimension of the array.
-
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
That can be simplified and corrected somewhat. Try this:
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,BANKNUM)=BOARDHEADER+((X+Y*(Peek(Start(BANKNUM)+BOARDX))*BOARDSTEPS))
ITEMLOC= Fn BOARDARRAY(X,Y,15)
If Peek(ITEMLOC+9)=0
Doke ITEMLOC+X1,X1INIT
Doke ITEMLOC+Y1,Y1INIT
Doke ITEMLOC+X2,X2INIT
Doke ITEMLOC+Y2,Y2INIT
Locate 20,20 : Print Deek( Fn BOARDARRAY(0,0,15)+X1)
Wait 30
Locate 20,20 : Print " "
Goto QUIT
End If
Next X
Next Y
QUIT:
End Proc
The offset cannot be greater than 9 because the elements start counting from 0 and there are only 10 byte elements in the structure size. If you use 10 as an offset, it will overwrite the high-byte of X1 (that's the bigger half of the 16-bit word) in the next element.
Also, since we are adding the offsets to ITEMLOC anyway, we can remove the offset parameter from the function, hence the simplification of that formula. Lastly, if you want to read back a 16-bit word instead of an 8-bit byte, you have to use Deek instead of Peek.
-
For some reason it brings out wrong values and it crashes with guru meditation. Let me post the source code here again so you can see my issue.
-
It's probably because you're reading from and writing to uninitialized memory. In all of my examples I've used bank 15 to store the board. For some unknown reason there is a bug that seems to have randomly crept into the code that seems to be based on the idea that banks 15 through 46 are the same thing. They aren't. Delete all occurrences of 15+X to the bank number in your source code and replace them with the constant 15. If you want more than one board active at a time, you'll have to initialize the additional banks yourself.
-
My mistake....I fixed the problem with displaying the value. I needed to put wait 100 underneath Doke X print out to see the result so far...there is just one bug...and that bug is the displaying the Y value if I am going from up to down or down to up with the dot selections. But if I am doing the dots from left to right or right to left the value results are 100% correct :D I am almost done here!
I am noticing when I am going from up to down or down to up there is an 8 point difference in the Y coordinate when it is stored in the bank for some reason.
While I am at it...I have done checking for the X1, Y1 as well and it always displays the value of Y1 instead of X1 and Y1 I do not know why on that part.
Finally, when I close the program I see that it puts everything in CHIP RAM...how can I force the program to bang all these variables and changes into FAST RAM? I want CHIP RAM to be only and only for graphics, sound and music and nothing else...I want to put all the mathematical calculation...I want to put all the arrays and customized structures..and everything else into FAST RAM only. In fact...I want pretty much the entire execution of the program on the FAST RAM leaving CHIP RAM completely free of all responsibilities except when I put Bob or sound or music then chip RAM will go down based on the graphics and audio and everything else all into FAST RAM.
I have attached the latest code here
-
The AMCAF extension has a "Bank To Fast" command, but be sure to check if there is sufficient Fast RAM available before moving stuff there.
Also, your bank handling code is still mixed up. You have BOARDX and BOARDY pointing to the same memory location and the header only big enough for one of them.
-
I do not understand what you mean by my boardx and boardy are pointing to the same memory location...in fact...why do I even need boardx and boardy? I do not get it. Why do I even need it all together? And you said they are pointing at the same memory location...isn't boardx=0 and boardy=1 two different values all together?
Ok.....by the way I still do not get how is this effect the last bit of problem I have? It seems it is almost finished and almost done except for two little bugs. One bug is when I am clicking the second dot underneath or top of the first dot click then the value returns with difference of 8.
The second problem I have is in the X1, Y1 of the ItemLoc+9 of the boardarray.
When I do peek X1 and Y1 it returns the value of Y1 (correctly) but put values of Y1 for X1 and Y1 variables instead of returning the value of X1 to X1 and Y1 to Y1? Are you telling me the reason behind that is because I am pointing to wrong memory location? Can you please show me how to point to different memory location and where exactly is the correct memory location I need to point. Because I do not know where their memory location are and I might actually point to a wrong location and cause a guru.
-
I'll go down through the listing line-by-line.
' flag indicating a valid hit
Set Buffer 256
Set Sprite Buffer 128
'On Error Goto LOWCHIPRAM
Global FH,RIGHT,LEFT,UP,BOTTOM,SELECTED,LGTH,CLICKED,CLICKEDX1,CLICKEDY1
Global LOCKED,CENTERCLICKEDX1,CENTERCLICKEDY1,LOCKEDRIGHT,LOCKEDLEFT,LOCKEDUP,LOCKEDDOWN
Global LASTDIRECTION
LOCKEDRIGHT=False : LOCKEDDOWN=False : LOCKEDLEFT=False : LOCKEDUP=False
' Turn=1 is for player 1 color red, Turn=2 is for player 2 color blue
Global TURN
Global BOARDX,BOARDY,BOARDHEADER,BOARDSTEPS,OFFSETX1,OFFSETY1,OFFSETX2,OFFSETY2
BOARDX=0 : BOARDY=0 : BOARDHEADER=2 : BOARDSTEPS=5 : BOARD=BOARDHEADER+(32*21*BOARDSTEPS)
Here are your first couple of errors. BOARDY should be 1. If BOARDSTEPS=5, you can't use offsets greater than 4 so you'll have to either make the other value stored separately in an array or increase BOARDSTEPS and use a new offset there.
Reserve As Work 15,BOARD
Poke Start(15)+BOARDX,32
Poke Start(15)+BOARDY,21
' Reset the values
LOCKED=False
' Countdown timer for the "Invalid Action!" display
' Hide everything until we have finished drawing:
Auto View Off
Screen Open 0,320,200,64,Lowres
Curs Off
Flash Off : Hide On : Rem Hide mouse pointer
Colour 0,$0
Colour 1,$FFF
Colour 2,$F00
'Colour 3,$FF0
'Colour 4,$FFF
Inverse Off
RIGHT=78 : UP=76 : BOTTOM=77 : LEFT=79 : SELECTED=0
' This colour represents your back IFF pic, just do not use
' colours 0 through 2 in the picture!
Cls 0
CLICKED=True
' Center your rectangular play area:
Global XO
XO=(320-256)/2
EC=35 : F=0 : LGTH=0 : ICOUNTER=0
Proc SETBOARD
Auto View On
DC=-1
'Proc _MISS["All results are suuccessful."]
FD=True : Rem flag for First Dot hit
SELECTEDX1=100
Screen Show 0
Load "dh0:linesformed.abk"
Get Bob Palette $0
Repeat
If Ntsc=0 : Exit : End If
Proc _MISS["?NTSC COMMODORE NOT SUPPORTED! REGION ERROR!"]
Until Ntsc=0
Repeat
Wait Vbl
MC=Mouse Click
K$=Inkey$
SELECTED=Scancode
If Not LOCKED
CLICKEDMAXX1=280 : CLICKEDMAXY1=4
CLICKEDMAXX2=36 : CLICKEDMAXY2=158
Else If LOCKED
If CENTERCLICKEDX1=CLICKEDX1 and CENTERCLICKEDY1=CLICKEDY1
If FINISHED1=0 : CLICKEDMAXX1=(CENTERCLICKEDX1+2) : FINISHED1=1 : End If
If FINISHED2=0 : CLICKEDMAXX2=(CENTERCLICKEDX1-2) : FINISHED2=1 : End If
If FINISHED3=0 : CLICKEDMAXY1=(CENTERCLICKEDY1-2) : FINISHED3=1 : End If
If FINISHED4=0 : CLICKEDMAXY2=(CENTERCLICKEDY1+2) : FINISHED4=1 : End If
LOCKEDDOWN=False : LOCKEDUP=False : LOCKEDLEFT=False : LOCKEDRIGHT=False
Else
If LASTDIRECTION=RIGHT
LOCKEDDOWN=True : LOCKEDUP=True
End If
If LASTDIRECTION=LEFT
LOCKEDDOWN=True : LOCKEDUP=True
End If
If LASTDIRECTION=UP
LOCKEDRIGHT=True : LOCKEDLEFT=True
End If
If LASTDIRECTION=BOTTOM
LOCKEDLEFT=True : LOCKEDRIGHT=True
End If
End If
End If
If CLICKEDX1<CLICKEDMAXX1
If SELECTED=RIGHT and LOCKEDRIGHT=False and SELECTED<>UP and SELECTED<>BOTTOM and SELECTED<>LEFT
Inc RIGHTINC
LASTDIRECTION=RIGHT
If Point(RIGHTINC*8+4+XO,UPINC*8+4)<>2
Proc _MOVE_NEXT_STEP[RIGHTINC,UPINC,XO]
ITISOKTOCLEAR=0
Else If ITISOKTOCLEAR=0
ITISOKTOCLEAR=1
Ink 1
X1=(RIGHTINC-1)*8+4+XO
Y1=UPINC*8+4
CENTERCLICKEDX1=X1 : CENTERCLICKEDY1=Y1
Bar X1-1,Y1-1 To X1+1,Y1+1
End If
End If
End If
If CLICKEDX1>CLICKEDMAXX2
If SELECTED=LEFT and LOCKEDLEFT=False and SELECTED<>RIGHT and SELECTED<>BOTTOM and SELECTED<>UP
Dec RIGHTINC
LASTDIRECTION=LEFT
If Point((RIGHTINC*8+4+XO),UPINC*8+4)<>2
_MOVE_NEXT_STEP[RIGHTINC,UPINC,XO]
ITISOKTOCLEAR=0
Else If ITISOKTOCLEAR=0
ITISOKTOCLEAR=1
Ink 1
X1=(RIGHTINC+1)*8+4+XO
Y1=UPINC*8+4
CENTERCLICKEDX1=X1 : CENTERCLICKEDY1=Y1
Bar X1-1,Y1-1 To X1+1,Y1+1
End If
End If
End If
If CLICKEDY1>CLICKEDMAXY1
If SELECTED=UP and LOCKEDUP=False and SELECTED<>BOTTOM and SELECTED<>LEFT and SELECTED<>RIGHT
Dec UPINC
LASTDIRECTION=UP
If Point((RIGHTINC*8+4+XO),UPINC*8+4)<>2
_MOVE_NEXT_STEP[RIGHTINC,UPINC,XO]
ITISOKTOCLEAR=0
Else If ITISOKTOCLEAR=0
ITISOKTOCLEAR=1
Ink 1
X1=RIGHTINC*8+4+XO
Y1=(UPINC+1)*8+4
Bar X1-1,Y1-1 To X1+1,Y1+1
CENTERCLICKEDX1=X1 : CENTERCLICKEDY1=Y1
End If
End If
End If
If CLICKEDY1<CLICKEDMAXY2
If SELECTED=BOTTOM and LOCKEDDOWN=False and SELECTED<>UP and SELECTED<>RIGHT and SELECTED<>LEFT
Inc UPINC
LASTDIRECTION=BOTTOM
If Point((RIGHTINC*8+4+XO),UPINC*8+4)<>2
_MOVE_NEXT_STEP[RIGHTINC,UPINC,XO]
ITISOKTOCLEAR=0
Else If ITISOKTOCLEAR=0
ITISOKTOCLEAR=1
Ink 1
X1=RIGHTINC*8+4+XO
Y1=(UPINC-1)*8+4
Bar X1-1,Y1-1 To X1+1,Y1+1
CENTERCLICKEDX1=X1 : CENTERCLICKEDY1=Y1
End If
End If
End If
If SELECTED=64
Proc CLICKED[RIGHTINC,UPINC,XO]
End If
' Simple right-click to exit for this demo:
'
Until MC=%10
End
Procedure CLICKED[X,Y,XO]
Shared CLICKED,PLYRCOLOR,CENTERCLICKEDX1,CENTERCLICKEDY1
Shared LOCKED,FINISHED,FINISHED1,FINISHED2,FINISHED3,FINISHED4
Shared LOCKEDUP,LOCKEDDOWN,LOCKEDLEFT,LOCKEDRIGHT
Shared BOARDSTEPS,BOARDX,BOARDY,BOARD,OFFSETX1,OFFSETY1,OFFSETX2,OFFSETY2
If CLICKED
If LOCKED=True
LOCKED=False : FINISHED1=0 : FINISHED=0 : FINISHED2=0 : FINISHED3=0 : FINISHED4=0
LOCKEDUP=False : LOCKEDDOWN=False : LOCKEDRIGHT=False : LOCKEDLEFT=False
If Point(X,Y)<>2
Ink 2
X1=X*8+4+XO
Y1=Y*8+4
Bar X1-1,Y1-1 To X1+1,Y1+1
End If
' Before we perform the final and last step of release the player
' to plot two more dots we will see if two lines can be formed here
For YCOUNTER=0 To 21
For XCOUNTER=0 To 32
Def Fn BOARDARRAY(X,Y,BANKNUM)=BOARDHEADER+((X+Y*(Peek(Start(BANKNUM)))*BOARDSTEPS))
ITEMLOC= Fn BOARDARRAY(XCOUNTER,YCOUNTER,15)
If Peek(ITEMLOC+9)=0
If boardsteps is less than 10 you can't use ITEMLOC+9.
Locate 20,20 : Print " "
Doke ITEMLOC+OFFSETX1,CENTERCLICKEDX1
If you use Doke instead of Poke, you have to use values OFFSETX1 that are even. Where is OFFSETX1 defined? I see that it is allocated as a global but I don't see where the value is set. If it isn't given a value, Amos will just use 0 for everything. This includes all of the field names of the custom type.
Locate 20,20 : Print "CtrClickedX1"+Str$(CENTERCLICKEDX1)
Wait 100
Locate 20,20 : Print " "
Locate 20,20 : Print "Deek X:"+Str$(Deek( Fn BOARDARRAY(XCOUNTER,YCOUNTER,15)+OFFSETX1))
Wait 100
Doke ITEMLOC+OFFSETY1,CENTERCLICKEDY1
Locate 20,20 : Print " "
Locate 20,20 : Print "CtrlickedY1"+Str$(CENTERCLICKEDY1) : Wait 100
Doke ITEMLOC+OFFSETX2,X1
Doke ITEMLOC+OFFSETY2,Y1
Locate 20,20 : Print " "
Locate 20,20 : Print "Deek Y:"+Str$(Deek( Fn BOARDARRAY(XCOUNTER,YCOUNTER,15)+OFFSETY1))
Wait 100 : Locate 20,20 : Print " "
Locate 20,20 : Print "X1 "+Str$(X1)+" Y1 "+Str$(Y1)
Wait 100
Locate 20,20 : Print " "
Locate 20,20 : Print "Deek X1:"+Str$(Deek( Fn BOARDARRAY(XCOUNTER,YCOUNTER,15)+OFFSETX2))+" Deek Y1 "+Str$(Deek( Fn BOARDARRAY(XCOUNTER,YCOUNTER,15)+OFFSETY2))+""
LOCKED=False
Goto SKIPPED : End If
Next XCOUNTER
Next YCOUNTER
End If
Ink 2
If Point(X,Y)<>2
X1=X*8+4+XO
Y1=Y*8+4
Bar X1-1,Y1-1 To X1+1,Y1+1
LOCKED=True : CENTERCLICKEDX1=X1 : CENTERCLICKEDY1=Y1
End If
SKIPPED:
Else
Proc _MISS["Invalid action!"]
End If
End Proc
Procedure _MOVE_NEXT_STEP[X,Y,XO]
' Move at the new location specificed
Shared SELECTED,RIGHT,LEFT,UP,BOTTOM,CLICKEDX1,CLICKEDY1
EIGHT=8 : FOUR=4 : NUMBERONE=1
If SELECTED=RIGHT and SELECTED<>LEFT and SELECTED<>UP and SELECTED<>BOTTOM
Ink 7
X3=X*EIGHT+FOUR+XO
Y3=Y*EIGHT+FOUR
CLICKEDX1=X3 : CLICKEDY1=Y3
Bar X3-NUMBERONE,Y3-NUMBERONE To X3+NUMBERONE,Y3+NUMBERONE
Proc _CLEARRIGHT[XO,X,Y]
End If
If SELECTED=UP and SELECTED<>RIGHT and SELECTED<>LEFT and SELECTED<>BOTTOM
Ink 7
X3=X*EIGHT+FOUR+XO
Y3=Y*EIGHT+FOUR
Bar X3-NUMBERONE,Y3-NUMBERONE To X3+NUMBERONE,Y3+NUMBERONE
' Clear the old location all together
CLICKEDX1=X3 : CLICKEDY1=Y3
Proc _CLEARUP[XO,X,Y]
End If
If SELECTED=LEFT and SELECTED<>RIGHT and SELECTED<>BOTTOM and SELECTED<>UP
Ink 7
X3=X*EIGHT+FOUR+XO
Y3=Y*EIGHT+FOUR
Bar X3-NUMBERONE,Y3-NUMBERONE To X3+NUMBERONE,Y3+NUMBERONE
' Clear the old location all together
CLICKEDX1=X3 : CLICKEDY1=Y3
Proc _CLEARLEFT[XO,X,Y]
End If
If SELECTED=BOTTOM and SELECTED<>UP and SELECTED<>LEFT and SELECTED<>RIGHT
Ink 7
X3=X*EIGHT+FOUR+XO
Y3=Y*EIGHT+FOUR
Bar X3-NUMBERONE,Y3-NUMBERONE To X3+NUMBERONE,Y3+NUMBERONE
CLICKEDX1=X3 : CLICKEDY1=Y3
' Clear the old location all together
Proc _CLEARBOTTOM[XO,X,Y]
End If
SELECTEDX1=X3 : SELECTEDY1=Y3
End Proc
Procedure _CLEARRIGHT[XO,X,Y]
Shared CLICKEDX1,CLICKEDY1
If Point(CLICKEDX1-8,CLICKEDY1)<>2
Ink 1
X=X-1
X1=X*8+4+XO
Y1=Y*8+4
Bar X1-1,Y1-1 To X1+1,Y1+1
End If
End Proc
Procedure _CLEARLEFT[XO,X,Y]
Shared CLICKEDX1,CLICKEDY1
If Point(CLICKEDX1+8,CLICKEDY1)<>2
Ink 1
X=X+1
X1=X*8+4+XO
Y1=Y*8+4
Bar X1-1,Y1-1 To X1+1,Y1+1
End If
End Proc
Procedure _CLEARBOTTOM[XO,X,Y]
Shared CLICKEDX1,CLICKEDY1
If Point(CLICKEDX1,CLICKEDY1-8)<>2
Ink 1
Y=Y-1
X1=X*8+4+XO
Y1=Y*8+4
Bar X1-1,Y1-1 To X1+1,Y1+1
End If
End Proc
Procedure _CLEARUP[XO,X,Y]
Shared CLICKEDX1,CLICKEDY1
If Point(CLICKEDX1,CLICKEDY1+8)<>2
Ink 1
Y=Y+1
X1=X*8+4+XO
Y1=Y*8+4
Bar X1-1,Y1-1 To X1+1,Y1+1
End If
End Proc
Procedure _MISS[WORDHERE$]
Shared LGTH
ICOUNTER=0
LGTH=Len(WORDHERE$)*-1
Repeat
For I=320 To(LGTH)*10 Step -1
Ink 2
Text I,195,WORDHERE$
For X=0 To 300 : Next
Next I
Inc ICOUNTER
Until ICOUNTER=1
End Proc
LOWCHIPRAM:
If Chip Free<30080
Repeat
Proc _MISS["?CHIP RAM IS TOO LOW!"]
Until Chip Free>50080
End If
Screen Open 0,320,200,8,Lowres
Auto View On : Curs Off : Hide On
Colour 0,$0 : Colour 1,$FFF : Colour 2,$F00 : Colour 3,$FF0 : Colour 4,$FFF
Screen Show 0 :
Repeat
Proc _MISS["Reason for error: "+Err$(Errn)+"."]
Until X=1
Procedure SETBOARD
Shared XO
Box XO+0,0 To XO+255,167
' This bar represents your background pic
Ink 3
Box XO+1,1 To XO+254,166
For X=0 To 31
For Y=0 To 20
X1=X*8+4+XO
Y1=Y*8+4
Ink 1
Bar X1-1,Y1-1 To X1+1,Y1+1
Ink 0
Box X1-2,Y1-2 To X1+2,Y1+2
Next Y
Next X
End Proc
-
By the way...thank you so much for everything and apologies if I am slow to grasping things...and apologies for keep asking...and I appreciate your severe patience and willing to help and also constantly replying to my problem.
I promise when my game is finished you will get credit first for all the effort you have done to help me get to understand coding in AMOS. Also I promise ones I get the hand of AMOS and start to enjoying developing on it...90% of my games will be developed on AMOS.
-
Thank you so much!!! It works 100% now when it comes to retrieving the values!!! This helped a lot!!! THANKS!
I should be finishing the program next week :D Then it will be released to the public with titles and everything!
-
You're welcome!
-
OK I am discovering another problem and it is frustrating me now. I think I have reached the frustrating level...thinking that maybe this time I solved it and I did not solve it:
Problems and issues listed below:
1) I am unable to initialize the entire boardarray(x,y) to zero and point to clear memory without causing Guru Meditation
2) It used to display the line correctly now it is not displaying it correctly at all
3) I tried to make an if statement where lineformed is 0 to draw a line between two specific points and it is not doing it...it is failing
4) Every time I click for two new dots the xcounter and ycounter are always zero...so it always loops at 0,0 for the board no matter what I do as if the values are not installed or placed at xcounter, ycounter so what end up happening
for ycounter = 0 to 21
for xcounter = 0 to 31
... do buggy coded stuff here...to prevent guru meditation I am forced to exit the loop statement as soon as the supposed value is stored there using Goto label..............
next xcounter
next ycounter
label:
....
The xcounter and ycounter is zero as it is the first time it looped. When I repeat again and press two dots again on the board and it loops again...ones more the xcounter, ycounter are zeros when it executes the buggy code it can never manage to do xcounter=1, ycounter=0 and so on....as if for some reason the values are not stored at all in boardarray at all.
Programming in AMOS is a little frustrating and not easy it seems....so if another month of constant attempting fails I am forced to scrap my project and switch languages....I really hope not to do that :(.
I do not know what to do!
-
The EXIT command (http://www.ultimateamiga.co.uk/HostedProjects/AMOSFactory/AMOSProManual/5/535.html) is usually preferred over the GOTO command when exiting loops. There is a risk of the stack being left with data in it from the FOR commands otherwise. If you need to exit 2 levels of loops, just do an EXIT 2. If you need to skip additional stuff at the end of the loop, use a flag value so that you can embed your stuff in an IF statement. I guess what I'm trying to say is that GOTO isn't always safe to use in AmosPro.
Looking at your code, some things are pointing at bank 15 and others at bank 16. Last I knew, you were only using one bank in your code and if this is still the case, you're trying to access memory from an uninitialized bank. That could give the illusion of corrupted memory.
-
Actually...the reason behind me using Bank 15 and 16...is because in Bank 15 I am only able to put two values: Offsetx1 and Offsety1...if I attempt to put more it will not work and crash and cause invalid number.
The other thing is...in Bank 15 I have not initialized it either...so when I am doing Peek(ItemLock+9) it is returning some jibberish unwanted number instead of 0 and I do Peek(itemlock+0) it starts off with zero..then gives me 24 or 58...and when I quit the program entirely and recompile it...it is stuck with 58
so this statement:
if Peek(ItemLock+0)=0
no longer works or executes....it is getting frustrating. I am wondering right now that if I am going to have major problem like this on a simple dot game...where the objective of the game and point of the game is so simple yet coding it is sooo complex and complicated (and it should not be)....what other further worse complication and limitation will I be facing if I want to go into more complex game development such as platforms,adventures and even AI monsters.
You have helped me so much and you have being on my side answering all my questions...thank you so much for everything you have done...I am thinking of changing ships and going to Blitz Basic. At least that programming language have NewType and handles arrays much better than AMOS.....these two simple features makes a huge DIFFERENCE for the programmer when he wants to make his project and could ultimately change his decision in which tool he uses to develop his projects.
-
Have you considered AmigaE? It supports object-oriented programming better than AmiBlitz if that interests you.
-
Seems a serious programming language :D I like that!!! I will learn all my skills on BlitzBasic 2...then migrate to AmigaE. Hey..look...I like AMOS...it is a sweet programming language and from games I saw made by it...it can pretty much do everything as any other programming language can do. It just does not meet my style at all....I am sure old programmers who are ok with not being object oriented and love hacking their code...and love manipulating memory in low level language style...and do not mind peeking and pooking and dooking and deeking would not mind this language and will find it comfortable. It just not my style here.
However, in the future..if you guys do decide to rework the entire engine of AMOS all together...and make it 100% object oriented with class and inheritance and libraries...then I will for sure consider returning back to it and making all my games on it!!!
-
It would be impractical to add OOP to AmosPro. Sidewinder and I tried to figure out a way to do that and it ultimately fell flat. If you need OOP, use AmigaE instead. If you need portability you can also try the sequel to AmigaE called PortablE (http://cshandley.co.uk/portable/PortablE.html) but as of this time, it takes too much memory to be used on a Classic Amiga even though it generates code that will work on those machines.