Quantcast
Channel: 'Designing a simple game in Pascal, would like some advice' Thread RSS Feed
Viewing all articles
Browse latest Browse all 4

Re: Designing a simple game in Pascal, would like some advice

$
0
0
: : Whenever you need to store a lot of data use either arrays or linked
: : lists. In this case a 2D-array will be best.
:
: All right, thanks. It took awhile, but I figured out how to create,
: edit, and properly display arrays.
:
: However, there's one thing I still need to know. Is it possible to
: use a single command to edit several (or all) variables in an array?
: If so, please tell me what it is, because I've been unable to find
: such a command in the tutorial I'm using.
:

Not really, although that is partially a lie. You can use a loop (most common method) to fill an array with all 'x' or 1 or whatever you are filling it with.
Another method is to use the FillChar() procedure. As long as your array is based on byte sizes, it will work:

VAR
   A : Array[1..10,1..20] Of Byte;
   B : Array[1..3,12..23,3..6] Of Char;
   C : Array[1..10] Of Word;

   
Begin
     FillChar(A,SizeOf(A),$21);   { <-- Fills with '!' }
     FillChar(B,SizeOf(B),'x');   { <-- Fills with 'x' }

     FillChar(C,SizeOf(C),$1012); { <-- ERROR! must be a BYTE or CHAR }
     FillChar(C,SizeOf(C),$40);   { <-- Works, but each C[] will be $4040,
                                        not $0040 as desired }
End.


As you can see this works for basic arrays. You could create your own FillCharW() procedure to do the same for any Word/Integer values if needed. (Using loops in a function or much faster using assembly ;)

Phat Nat

Viewing all articles
Browse latest Browse all 4

Trending Articles