Author Topic: Multi Dimintion Arrays - Solved -  (Read 1175 times)

0 Members and 1 Guest are viewing this topic.

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Multi Dimintion Arrays - Solved -
« on: July 18, 2009, 04:47:19 pm »
Is it possible to have multi dimintional arrays? Im thinking if pascal will allow it it would look something like this:
Code: [Select]
multiarray: array[1..32] of array[1..10] of byte

If this wont work I will just use a record with 10 byte values, but this would be easyer and loop friendly.
« Last Edit: July 20, 2009, 03:48:57 pm by Hacktank »


Offline CurryWurst

  • Camper
  • ***
  • Posts: 265
    • Soldat Global Account System
Re: Multi Dimintion Arrays
« Reply #1 on: July 18, 2009, 04:59:49 pm »
Indeed, the syntax is exactly how you have written it, but do not forget to put a semicolon at the end :P For dynamic multi dimensional arrays just leave out the index range.
« Last Edit: July 18, 2009, 05:02:16 pm by CurryWurst »
Soldat Global Account System: #soldat.sgas @ quakenet

Offline croat1gamer

  • Veteran
  • *****
  • Posts: 1327
  • OMG CHANGING AVATAR!!! ^ω^
Re: Multi Dimintion Arrays
« Reply #2 on: July 18, 2009, 05:02:28 pm »
It is.
http://www.learn-programming.za.net/programming_pascal_learn07.html

BUT, you need to know which array means what.

You forgot at the end to add ";".


I experimented with an 3rd diminition, but i got lost when repeating the multiarray[a][b.][c] a few times.

edit:
As curt said.
I was getting the link to it so he rushed in. :P

Ignore the dot in [b.], bold code prevention.
« Last Edit: July 18, 2009, 05:04:28 pm by croat1gamer »
Last year, I dreamt I was pissing at a restroom, but I missed the urinal and my penis exploded.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Multi Dimintion Arrays
« Reply #3 on: July 18, 2009, 10:43:28 pm »
Actually im Curt lol

imo, multidimensional arrays are matrix-like (but in n dimensions), so that each element's array length count are equal.. something like array[1..32, 1..10] of byte; but this is not possible as far as i remember in Soldat pascal

and yes, as noted before, your exactly correct but with a semi-colon ';' at the end

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: Multi Dimintion Arrays
« Reply #4 on: July 19, 2009, 09:48:48 pm »
Thanks guys, i know its possible in other langs but i was just wondering if soldat pascal would support it.

EDIT:
I cant get it to work, if i try to call it like this:
Code: [Select]
waves: array[1..maxwaves] of array[1..17] of byte;
...
waves[i].[wep] := ....
I get a simicolon expected error, how am i supposed to call it? It gives a close block expected error if I do waves[i,wep] :=.

Thank you for the help guys.
« Last Edit: July 20, 2009, 02:27:26 am by Hacktank »


Offline Toumaz

  • Veteran
  • *****
  • Posts: 1904
Re: Multi Dimintion Arrays - Not Solved -
« Reply #5 on: July 20, 2009, 04:26:36 am »
Try:

Code: [Select]
waves[i][wep]

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Multi Dimintion Arrays - Not Solved -
« Reply #6 on: July 20, 2009, 12:15:59 pm »
What Toumaz said...

Code: [Select]
const
  maxwaves = 5;

var
  waves: array[1..maxwaves] of array[1..17] of byte;

pocedure ActivateServer();
var
  i, j: byte;
begin
  for i := 1 to maxwaves do
    for j := 1 to 17 do
      waves[i][j] := 0;
end;

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: Multi Dimintion Arrays - Not Solved -
« Reply #7 on: July 20, 2009, 02:57:05 pm »
Thanks guys, i figured it needed a .. I have one more question: how would i go about using setarraylength and getarraylength with mulidim arrays?


Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Multi Dimintion Arrays - Not Solved -
« Reply #8 on: July 20, 2009, 03:25:05 pm »
I'll supply an example:

Code: [Select]
var
  myVar: array[1..10] of array of array[5..6] of integer;

procedure ActivateServer();
var
  i, j, k: integer;
begin
  for i := 1 to 10 do begin
    SetArrayLength(myVar[i], Random(1, 15));
    for j := 0 to GetArrayLength(myVar[i]) - 1 do
      for k := 5 to 6 do
        myVar[i][j][k] := i + j + k + Random(1, 200);
  end;
end;

This does absolutely nothing useful btw :P
verbal explanation of wtf happened in the example:
in each of the 10 elements of the first array, it will set the length of that array to a random number between 1 and 14 inclusive; and in each of these arrays, there is an array going from 5 to 6, each containing an integer, which is set to the sum of i, j, k, and a random number between 1 and 199 inclusive.

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: Multi Dimintion Arrays - Not Solved -
« Reply #9 on: July 20, 2009, 03:48:49 pm »
Thanks man, your the greatest, i get it now.