Page 1 of 1

3 dimensional arrays, i think?

Posted: Fri Mar 18, 2005 2:56 pm
by Agent_Firestalker
I believe that what they're called. follow me with this angle...

Troop.group,str,agi,hp(1)

that defines a soldier in a group and gives his strength, agility, and life.
i hope.

but how do I read the str, agi, hp, etc.. from this array. Will each array have to have different names (str1, agi2, agi5, hp4) or can I use what i've got? If i read the stats and then print them onto the screen and assign each menu choice (selecting the soldier for the task) to a troop.group.

I am doing this right. If not, correct me.

thanx
Agent_Firestalker

Posted: Sun Mar 20, 2005 9:19 am
by Mitth'raw'nuruodo
You only need 1 array:
First you need to know: The Types of Variables:

An Integer is a whole number type of variable. It can be from -32,768 to 32,767.

A Long is a whole number type of variable. It can be from -2, 147, 483, 648 to 2, 147, 483, 647.

A String is a word variable. But you should know this. SringName$ = "Hello" is an example. It can be from 0 to 32, 767 characters.

A Single precision is a decimal number variable.

A Double is a decimal number variable. It's like a Long Single.

TO DEFINE A YOUR array:

Code: Select all

TYPE TypeName
  group AS INTEGER  'or whatever other variable type you want(STRING must have an n* and a number after it for how long the string will be)
  str AS INTEGER
  agility AS INTEGER
  life AS INTEGER
END TYPE
DIM Troop(min TO max) AS TypeName 'put in values for min and max
To access your values do:

Code: Select all

'Note: the PRINT is optional (of course), index is your normal index of the array number
PRINT Troop(index).group
PRINT Troop(index).str
PRINT Troop(index).agility
PRINT Troop(index).life
Troop(index).group = 1
Troop(index).str = 2
'etc.
If you what to know how to use them as parameters in subs just ask.
Hope that helps! :D

Posted: Tue Mar 22, 2005 10:33 pm
by Agent_Firestalker
I think the talks about strings and double precision are fine, just save them for real noobs. I was actually trying to get an array where each part connects to the beginning. (i.e....

Troop.group, str, agi, hp

for each troop member (troop.group = 1 to 25, 25 different guys)
if troop.group = 1 then str, agi, and hp relate to his stats.
like if I load troop.group = 1 then str and agi = 11 and hp = 23, but if I load group 2 then str and agi = 5 and hp = 10.
So i can write stats to each member's number (troop.group)
is this possible? (hope it's not confusing.)

thanx
Agent_Firestalker

Posted: Thu Mar 24, 2005 4:40 pm
by Mitth'raw'nuruodo
Yes. You want Child Objects to your Parent Objects. (Troop.group1.hp)
Note you can't have arrays in TYPEs.

You can do it two ways:
Way I preferr(less typeing)

Code: Select all

TYPE TroopType
  str AS INTEGER
  agi AS INTEGER
  hp AS INTEGER
END TYPE
DIM Troop(1 TO 25) AS TroopType

'ex. To get access to group say 5's hp you just do:
Troop(5).hp = 3450
'ex. To get access to group 12's str you just do:
Troop(12).str
Parent-Child Object thing:

Code: Select all

TYPE GroupType
  str AS INTEGER
  agi AS INTEGER
  hp AS INTEGER
END TYPE
'Note: group below CANNOT be an array, this is why I hate doing it this way:
TYPE TroopType
  group1 AS GroupType
  group2 AS GroupType
  group3 AS GroupType
  group4 AS GroupType
  'etc. up to 25
END TYPE
DIM Troop AS TroopType

'Now to access group #5's hp you do:
Troop.group5.hp = 123
'To get to group 12's str:
Troop.group12.str = 1
Well there you go again.
I preffer the first way when doing what your talking about.... :wink:

Posted: Sat Mar 26, 2005 12:06 am
by xeonrebel
"You only need 1 array:
First you need to know: The Types of Variables:

An Integer is a whole number type of variable. It can be from -32,768 to 32,767.

A Long is a whole number type of variable. It can be from -2, 147, 483, 648 to 2, 147, 483, 647.

A String is a word variable. But you should know this. SringName$ = "Hello" is an example. It can be from 0 to 32, 767 characters.

A Single precision is a decimal number variable.

A Double is a decimal number variable. It's like a Long Single. "
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
hi, i've been wanting to ask this for a long time.

when do you use a variable of certain type?, ie: when and why to use an integer vs a Long, the same question goes for single vs double.

and what are the advantages-disadvantages of each (except string$ of course)

thankss
xeonrebel

Posted: Sat Mar 26, 2005 9:44 am
by Mitth'raw'nuruodo
Ok, well in QB you don't need to define a variable, QB does that for you. And the only variable symbol you need is the $ for string but you knew that.

However QB does go slower because it needs to figure out for itself what variables are what type or what. But you can use variable symbols (!, #, $, %, &) to define them yourself so QB doesn't have to.

But anyways to your question:
! = Single Precision -->Use this if you want only like 5 decimal places
# = Double Precision-->Use this if you want more decimal places than single
$ = String -->You know
% = Integer-->Use this if you want whole numbers to like 32K + or -
& = Long-->Use this if you want a whole number to like 2Bil + or -

Things like Double and Long use more memory than Single or Integer.

If you are working with numbers and you want VERY precise calc. you would use doubles(ex. calc. Planitary orbits :lol: ).

When you are working with decimals but not long decimals you use singles (ex. Calculating Vectors).

When your working with small whole numbers you use integers (ex. Calc. a sprite's coordinate on the screen).

When you are using long whole numbers you would use Long (ex. a ship's hit points).

Hope that helps. :D