Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
An equipment screen for my RPG game
#4
@SMcNeill, why ReDim here? You only use ReDim if you want to change the dimension of an array: from XYZ(12) - ReDim XYZ(15), for example. And it is only applicable to dynamic arrays.
Is this a dynamic array? - I have to check it first, that is a problem of lack of practice.

Where does count come from? Have you tried that? ReDim _Preserve enemy(count): Here the dimension is permanently increased from 1.  To see if it works, one would have to try it out in a program.

Code: (Select All)

Type equipment_type 'assign the various types to your TYPE field
  name As String
  damage As Integer
  defense As Integer
  durability As Integer
  count As Integer
End Type

Dim Shared equipment(20) As equipment_type 'define your variable or array based off that field

Type enemy_type 'the same for the enemies
  name As String
  damage As Integer
  defense As Integer
  health As Integer
End Type

Dim Shared enemy(20) As enemy_type 'assign that type to an array, like above

Init_Enemy
Init_Equipment

Sub Init_Enemy
  ReDim enemy(200) As enemy_type 'Here is ReDim OK. You have changed the dimension. But why the same type declaration again?
  Restore enemy_data 'always use restore to make certain you get the data you want.
  Do

    Read enemy(count).name, enemy(count).damage, enemy(count).defense, enemy(count).health
    If enemy(count).name <> "EOD" Then
      count = count + 1
    Else
      Exit Do
    End If
  Loop
  ReDim _Preserve enemy(count) As enemy_type 'The same
  Exit Sub
  enemy_data:
  Data "Rabbit",2,0,6
  Data "Crab",3,1,6
  Data "EOD",-1,-1,-1 'end of data fields
End Sub

Sub Init_Equipment
  ReDim equipment(200) As equipment_type 'define your variable or array based off that field
  Restore equipment_data 'always use restore to make certain you get the data you want.
  Do
    Read equipment(count).name
    Read equipment(count).damage, equipment(count).defense, equipment(count).durability
    Read equipment(count).count
    If enemy(count).name <> "EOD" Then
      count = count + 1
    Else
      Exit Do
    End If
  Loop
  ReDim _Preserve equipment(count) As equipment_type
  Exit Sub

  equipment_data:
  Data "Bone Spear",2,0,20,0
  Data "Flint Spear",4,0,30,0
  Data "Copper Spear",6,0,40,0
  Data "Iron Spear",8,0,50,0
  Data "Stone Axe",1,1,20,0
  Data "Copper Axe",3,2,35,0
  Data "Iron Axe",4,4,50,0
  Data "EOD",-1,-1,-1,-1
End Sub
Reply


Messages In This Thread
An equipment screen for my RPG game - by Delsus - 03-26-2024, 09:41 AM
RE: An equipment screen for my RPG game - by Kernelpanic - 03-26-2024, 05:23 PM



Users browsing this thread: 2 Guest(s)