Posts: 20
Threads: 5
Joined: Mar 2024
Reputation:
7
03-26-2024, 09:41 AM
(This post was last modified: 03-26-2024, 01:34 PM by Delsus.)
Hello team!
Here is my first message on this forum.
I have been asking a few questions on the Discord and thanks to people, I have been able to get this far, but this one requires a forum post.
First of all, I would like to mention that I'm quite a beginner and that I have still a lot to learn - and I'm eager to.
I am currently programming a survival text-based game with RPG elements.
It is basically a loop, with several SELECT CASE. Many functionalities are already in place and working properly : status bars, exploration, building, crafting etc...
There is also a draft for an inventory system, basically only displaying owned items (no interaction with them yet).
I programmed a simple combat system as well, however for it to be fully-fledged, I would need an equipment screen to add weapons and armor which add damage and defense in order to defeat stronger enemies.
This equipment screen would be comprised of about 6 slots, with two-handed weapons taking two slots at once and would look like that :
Code: (Select All)
FUNCTION equipScreen()
CLS
PRINT "Equipment Screen"
PRINT " [Right Hand] " 'here maybe show the variables of the equipment ? equipmentname; equipmentdamage; equipmentdefense; equipmentdurability ?
PRINT " [Left Hand] "
PRINT " [Gloves] "
PRINT " [Armor] "
PRINT " [Shoes] "
PRINT " [Helmet] "
PRINT
PRINT " (E)quip (U)nequip (B)ack"
END FUNCTION
For that, I think I would need arrays, but I don't know in which category to put what and what.
Here is the code I have so far. Let me know how I could improve it, as it doesn't work at the moment.
Would you know what I'm missing/doing wrong, please? I receive the error "Illegal SUB/FUNCTION parameter". I think I'm confused between all those variables, TYPEs and Arrays
Thank you in advance for your help!
Code: (Select All)
DIM enemy (20) as STRING '----- DIM Array or Type?
DIM Shared playername as STRING
DIM Shared damage as INTEGER
DIM Shared defense as INTEGER
DIM Shared health as INTEGER
'base combat stats
playername = ""
damage = 2
defense = 0
health = 100
DIM equip(50) AS equipment '----- DIM Array or Type?
'TYPE equipment ' -------Type or DIM Array ?
' shownname AS STRING
'damage AS INTEGER
'defense AS INTEGER
'durability AS INTEGER
'slot AS INTEGER
'END TYPE
dim rabbitname as string 'rabbit enemy ---------- Shall I perhaps use a TYPE for "enemy" ?
dim rabbitdamage as integer
dim rabbitdefense as integer
dim rabbithealth as integer
rabbitname = "Rabbit"
rabbitdamage = 2
rabbitdefense = 0
rabbithealth = 6
dim crabname as string 'crab enemy
dim crabdamage as integer
dim crabdefense as integer
dim crabhealth as integer
crabname = "Crab"
crabdamage = 3
crabdefense = 1
crabhealth = 6
TYPE equipment
equipmentname AS STRING
equipmentdamage AS INTEGER
equipmentdefense AS INTEGER
equipmentdurability AS INTEGER
END TYPE
bonespear.equipmentname = "Bone spear" ' ---------- Will this work with TYPE ?
bonespear.equipmentdamage = 2
bonespear.equipmentdefense = 0
bonespear.equipmentdurability = 20
bonespearcount = 0
flintspear.equipmentname = "Flint spear"
flintspear.equipmentdamage = 4
flintspear.equipmentdefense = 0
flintspear.equipmentdurability = 30
flintspearcount = 0
copperspear.equipmentname = "Copper spear"
copperspear.equipmentdamage = 6
copperspear.equipmentdefense = 0
copperspear.equipmentdurability = 40
copperspearcount = 0
ironspear.equipmentname = "Iron spear"
ironspear.equipmentdamage = 8
ironspear.equipmentdefense = 0
ironspear.equipmentdurability = 50
ironspearcount = 0
stoneaxe.equipmentname = "Stone axe"
stoneaxe.equipmentdamage = 1
stoneaxe.equipmentdefense = 1
stoneaxe.equipmentdurability = 20
stoneaxecount = 0
copperaxe.equipmentname = "Copper axe"
copperaxe.equipmentdamage = 3
copperaxe.equipmentdefense = 2
copperaxe.equipmentdurability = 35
copperaxecount = 0
ironaxe.equipmentname = "Iron axe"
ironaxe.equipmentdamage = 4
ironaxe.equipmentdefense = 4
ironaxe.equipmentdurability = 50
ironaxecount = 0
After that, I would need several more FUNCTIONs I guess, to select equipment, see its stats, put it in a slot, see the new player stats and remove it from the slots.
I have tried to write the code for that, but I don't understand what I'm really doing, as I don't know if I should use TYPE or DIM Arrays, and in what order.
Code: (Select All)
DIM slot as INTEGER
FUNCTION displayEquipment()
PRINT "Equipment:"
PRINT " Weapon: "; equip(0).shownname; " (Damage: "; equip(0).damage; ", Defense: "; equip(0).defense; ", Durability: "; equip(0).durability; ")"
PRINT " Left Hand: "; equip(1).shownname ; " (Damage: "; equip(1).damage; ", Defense: "; equip(1).defense; ", Durability: "; equip(1).durability; ")"
PRINT " Gloves: "; equip(2).shownname ; " (Damage: "; equip(2).damage; ", Defense: "; equip(2).defense; ", Durability: "; equip(2).durability; ")"
PRINT " Armor: "; equip(3).shownname ; " (Damage: "; equip(3).damage; ", Defense: "; equip(3).defense; ", Durability: "; equip(3).durability; ")"
PRINT " Shoes: "; equip(4).shownname ; " (Damage: "; equip(4).damage; ", Defense: "; equip(4).defense; ", Durability: "; equip(4).durability; ")"
PRINT " Helmet: "; equip(5).shownname ; " (Damage: "; equip(5).damage; ", Defense: "; equip(5).defense; ", Durability: "; equip(5).durability; ")"
END FUNCTION
FUNCTION equipItem (slot AS INTEGER, item AS equipment)
' Equip the item in the specified slot
equip(slot) = item
END FUNCTION
FUNCTION unequipItem(slot AS INTEGER)
' Unequip the item in the specified slot
equip(slot).name = ""
equip(slot).damage = 0
equip(slot).defense = 0
equip(slot).durability = 0
END FUNCTION
DIM equipmentchoice$ 'AS STRING in that case
DIM selectedSlot AS INTEGER
DIM selectedItem AS eqItem
initEquip()
DO
equipScreen()
INPUT "Enter your choice: "; equipmentchoice$
SELECT CASE equipmentchoice$
CASE "E"
INPUT "Enter the slot number: "; selectedSlot
IF selectedSlot >= 0 AND selectedSlot < 6 THEN
INPUT "Enter the item number: "; selectedItem
equipItem(selectedSlot, selectedItem)
END IF
CASE "U"
INPUT "Enter the slot number: "; selectedSlot
IF selectedSlot >= 0 AND selectedSlot < 6 THEN
unequipItem(selectedSlot)
END IF
CASE "B"
EXIT DO
END SELECT
displayEquipment()
LOOP
Posts: 3,978
Threads: 177
Joined: Apr 2022
Reputation:
220
03-26-2024, 01:51 PM
(This post was last modified: 03-26-2024, 02:06 PM by bplus.)
declare types first thing in code and fucntions go after main code.
then you can dim a single varaible as a type or make an array of the type.
Code: (Select All) Type equipment
equipmentname As String
equipmentdamage As Integer
equipmentdefense As Integer
equipmentdurability As Integer
End Type
type enemies
name as string
as integer damage, defense, durability
end type
dim bonespear as equipment ' do this first but you don't need the equipment name in type if you want to say bonespear.damage = 4
bonespear.equipmentname = "Bone spear" ' ---------- Will this work with TYPE ? yes
bonespear.equipmentdamage = 2
bonespear.equipmentdefense = 0
bonespear.equipmentdurability = 20
bonespearcount = 0
' either go by name and list.qualities or go by number and include the name in the type definition
dim foes(nEnemies) as enemies
foes(1).name = rabbit
foes(1).damage = ....
b = b + ...
Posts: 2,698
Threads: 327
Joined: Apr 2022
Reputation:
217
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
ReDim 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
ReDim 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 'large enough to hold all enemies in one array
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
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
I'm thinking a data structure like the above is what would suit your needs the best.
Posts: 1,002
Threads: 50
Joined: May 2022
Reputation:
27
03-26-2024, 05:23 PM
(This post was last modified: 03-26-2024, 05:35 PM by Kernelpanic.)
@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
Posts: 2,698
Threads: 327
Joined: Apr 2022
Reputation:
217
(03-26-2024, 05:23 PM)Kernelpanic Wrote: @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
How did you end up with the code you did? Did you remove the ReDim from what I'd posted? (Compare your DIM SHARED statements to what is in my original post.)
The idea behind this type of data structure is ease of expandability. At the moment, there's only 2 monsters in the game -- rabbits and crabs. I'm certain that number is going to increase in the future. How far is it going to increase??
Who can say at this point in the game development! Maybe 10 monsters. Maybe 32. Maybe 114...
So with this uncertainty in play, we set up our code to do a few basic things:
1) Create an array large enough to hold all those possibiile options.
Code: (Select All) Sub Init_Enemy
ReDim enemy(200) As enemy_type 'large enough to hold all enemies in one array
Then we run a loop to count and keep track of how many enemies we actually have.
Code: (Select All) 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
The above loads data into our array, starting at element 0, and then increasing the count by 1 for each enemy entry, until it reaches the "End Of Data" field and stops.
3) We then resize that overlarge array down to the point where it *only* holds the data that it needs to.
Code: (Select All) ReDim _Preserve enemy(count) As enemy_type
In this case, we have 2 valid enemies (which would be in index 0 and 1, respectively) and the "End of Data" entry (which is in index 2). We counted them as we added them in the loop, so this ReDim Preserve trncates the array from 200 elements down to 2 elements, freeing unused memory and keeping our overall footprint as small as possible.
Does it work?
Certainly it does. I use this approach all the time, and there's probably a hundred different examples on the forums here where I've used it in the past. If youu need a testable program for this, here's a very simple one for you:
Code: (Select All)
Screen _NewImage(800, 600, 32)
ReDim num(1000) As Integer
Do
Read num(count)
If num(count) <> -1 Then count = count + 1 Else Exit Do
Loop
ReDim _Preserve num(count) As Integer
Print "There were "; count;
Print "numbers counted and stored in our array (with end of data marker of -1)"
Print "They were:"
Print "(Index)", "(Value)"
For i = 0 To UBound(num)
Print i, num(i)
Next
End
Data 1,2,3,4,5,6,7,8,9,-1
My array starts out insanely large, to make certain it'll hold my data. I then read and count my data. And when that is finished, I simply resize the array to hold *only* the data that it actually needs, while freeing up all that unused space.
It's quick. It's efficient. It's my general goto method for loading data into arrays -- whether it be from DATA statements, or from CSV files or such.
Posts: 1,272
Threads: 119
Joined: Apr 2022
Reputation:
100
I saw the use of REDIM twice as well and thought, huh, what's going on here. It's much more efficient than many of the ways I've used it in the past.
Normally I would use a counter, increase the array in size using that counter while preserving existing data, and then add the new data. That constant resizing and preserving in the loop took time.
Steve's method of creating a large array, reading the data in a loop, and then resizing afterward is much cleaner in my opinion and a technique I plan to implement from now on where appropriate.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Posts: 1,002
Threads: 50
Joined: May 2022
Reputation:
27
Yes, I modified ReDim to try it out.
An array created with ReDim is automatically declared as a dynamic array. So far so good. Now when I comment out Data I get an error saying "Read..." and I don't know why. Why is it “Out of Data” now?
The part with the for loop is clear, but the top part is not clear to me.
I'm afraid I'll have to create a corresponding program to understand what's going on.
Code: (Select All)
Screen _NewImage(800, 600, 32)
ReDim num(1000) As Integer
Do
Read num(count)
Print num
If num(count) <> -1 Then count = count + 1 Else Exit Do
Loop
ReDim _Preserve num(count) As Integer
Print "There were "; count;
Print "numbers counted and stored in our array (with end of data marker of -1)"
Print "They were:"
Print "(Index)", "(Value)"
For i = 0 To UBound(num)
Print i, num(i)
Next
End
'Data 1,2,3,4,5,6,7,8,9,-1
Posts: 2,698
Threads: 327
Joined: Apr 2022
Reputation:
217
03-26-2024, 06:51 PM
(This post was last modified: 03-26-2024, 06:54 PM by SMcNeill.)
(03-26-2024, 06:28 PM)TerryRitchie Wrote: I saw the use of REDIM twice as well and thought, huh, what's going on here. It's much more efficient than many of the ways I've used it in the past.
Normally I would use a counter, increase the array in size using that counter while preserving existing data, and then add the new data. That constant resizing and preserving in the loop took time.
Steve's method of creating a large array, reading the data in a loop, and then resizing afterward is much cleaner in my opinion and a technique I plan to implement from now on where appropriate.
If you guys would like to see an example of the speed difference in the two methods, here's one for you:
Code: (Select All)
ReDim foo(0) As Long 'the array that's going to hold an uncertain amount of data
Randomize Timer
limit = Rnd * 1000000 + 1000000 'now, nobody knows how large this limit is going to be. Right?
'Let's run some tests with various ways to fill an array with this uncertain amount of data
t# = Timer(0.001)
count = 0
Do
foo(count) = count
If count < limit Then
count = count + 1
ReDim _Preserve foo(count)
Else
Exit Do
End If
Loop
t1# = Timer(0.001)
Print Using "There were ###,###,### items in the array, and it took us ##.### seconds to fill it."; UBound(foo), t1# - t#
'Now, let's clear all that data and try a different method
ReDim foo(10000000) As Long 'big enough to hold the data, no matter what
t# = Timer(0.001)
count = 0 'reset the counter
Do
foo(count) = count
If count < limit Then
count = count + 1
Else
Exit Do
End If
Loop
ReDim _Preserve foo(count)
t1# = Timer(0.001)
Print Using "There were ###,###,### items in the array, and it took us ##.### seconds to fill it."; UBound(foo), t1# - t#
Run it a few times, as it generates a random sized array, and you can easily see the difference in performance here -- and this is with just a very simple LONG data structure. Make this an UDT and have it move/resize records that contain dozens of pieces of information and see how much the performance varies.
For 1.5 million items here, I'm getting times of 1.803 seconds to resize and rebild that LONG array one element at a time.
For the same 1.5 million items, I'm getting times of 0.024 seconds to load the data all at once and then resize it down after it's finished.
That's what? 80 times faster, give or take a few?
Just as simple to code. Much faster and more efficient. Is there any reason why one wouldn't use this type of method to load data into resizable arrays?
(03-26-2024, 06:47 PM)Kernelpanic Wrote: Yes, I modified ReDim to try it out.
An array created with ReDim is automatically declared as a dynamic array. So far so good. Now when I comment out Data I get an error saying "Read..." and I don't know why. Why is it “Out of Data” now?
The part with the for loop is clear, but the top part is not clear to me.
I'm afraid I'll have to create a corresponding program to understand what's going on.
Code: (Select All)
Screen _NewImage(800, 600, 32)
ReDim num(1000) As Integer
Do
Read num(count)
Print num
If num(count) <> -1 Then count = count + 1 Else Exit Do
Loop
ReDim _Preserve num(count) As Integer
Print "There were "; count;
Print "numbers counted and stored in our array (with end of data marker of -1)"
Print "They were:"
Print "(Index)", "(Value)"
For i = 0 To UBound(num)
Print i, num(i)
Next
End
'Data 1,2,3,4,5,6,7,8,9,-1
It's out of Data because you remarked out the DATA statement. See the last line in your code.
Posts: 20
Threads: 5
Joined: Mar 2024
Reputation:
7
03-26-2024, 07:00 PM
(This post was last modified: 03-26-2024, 07:08 PM by Delsus.)
Thank you for your messages!
I was able to reorder the equipment as TYPE and it seems to work :
Code: (Select All)
Type equipment
equipmentname AS STRING
equipmentdamage AS INTEGER
equipmentdefense AS INTEGER
equipmentdurability AS INTEGER
equipmentcount AS INTEGER
End Type
DIM bonespear AS equipment
bonespear.equipmentname = "Lance en os" 'game's language is actually in French.
bonespear.equipmentdamage = 2
bonespear.equipmentdefense = 0
bonespear.equipmentdurability = 20
bonespear.equipmentcount = 0
DIM flintspear AS equipment
flintspear.equipmentname = "Lance en silex"
flintspear.equipmentdamage = 4
flintspear.equipmentdefense = 0
flintspear.equipmentdurability = 30
flintspear.equipmentcount = 0
DIM copperspear AS equipment
copperspear.equipmentname = "Lance en cuivre"
copperspear.equipmentdamage = 6
copperspear.equipmentdefense = 0
copperspear.equipmentdurability = 40
copperspear.equipmentcount = 0
DIM ironspear AS equipment
ironspear.equipmentname = "Lance en fer"
ironspear.equipmentdamage = 8
ironspear.equipmentdefense = 0
ironspear.equipmentdurability = 50
ironspear.equipmentcount = 0
DIM stoneaxe AS equipment
stoneaxe.equipmentname = "Hache en pierre"
stoneaxe.equipmentdamage = 1
stoneaxe.equipmentdefense = 1
stoneaxe.equipmentdurability = 20
stoneaxe.equipmentcount = 0
DIM copperaxe AS equipment
copperaxe.equipmentname = "Hache en cuivre"
copperaxe.equipmentdamage = 3
copperaxe.equipmentdefense = 2
copperaxe.equipmentdurability = 35
copperaxe.equipmentcount = 0
DIM ironaxe AS equipment
ironaxe.equipmentname = "Hache en fer"
ironaxe.equipmentdamage = 4
ironaxe.equipmentdefense = 4
ironaxe.equipmentdurability = 50
ironaxe.equipmentcount = 0
CASE 20 'Description des equipments 'case 20 of my SELECT CASE loop --- I can show each equipment attributes.
CLS
Print "Description de l'‚quipement"
print ""
If bonespear.equipmentcount >= 1 THEN
X = (POS(0) - 1) * _FONTWIDTH
Y = (CSRLIN - 1) * _FONTHEIGHT
bonespearcount& = _LOADIMAGE("bonespear.png", 32)
print " Lance en os :" bonespear.equipmentcount; " Degats : " bonespear.equipmentdamage; " Defense : " bonespear.equipmentdefense; " Durabilite : " bonespear.equipmentdurability
_PUTIMAGE (X, Y), bonespearcount&
print ""
_FREEIMAGE bonespearcount&
Else
end if
If flintspear.equipmentcount >= 1 THEN
X = (POS(0) - 1) * _FONTWIDTH
Y = (CSRLIN - 1) * _FONTHEIGHT
flintspearcount& = _LOADIMAGE("flintspear.png", 32)
print " Lance en silex :" flintspear.equipmentcount; " Degats : " flintspear.equipmentdamage; " Defense : " flintspear.equipmentdefense; " Durabilite : " flintspear.equipmentdurability
_PUTIMAGE (X, Y), flintspearcount&
print ""
_FREEIMAGE flintspearcount&
Else
end if
If copperspear.equipmentcount >= 1 THEN
X = (POS(0) - 1) * _FONTWIDTH
Y = (CSRLIN - 1) * _FONTHEIGHT
copperspearcount& = _LOADIMAGE("copperspear.png", 32)
print " Lance en cuivre :" copperspear.equipmentcount; " Degats : " copperspear.equipmentdamage; " Defense : " copperspear.equipmentdefense; " Durabilite : " copperspear.equipmentdurability
_PUTIMAGE (X, Y), copperspearcount&
print ""
_FREEIMAGE copperspearcount&
Else
end if
If ironspear.equipmentcount >= 1 THEN
X = (POS(0) - 1) * _FONTWIDTH
Y = (CSRLIN - 1) * _FONTHEIGHT
ironspearcount& = _LOADIMAGE("ironspear.png", 32)
print " Lance en fer :" ironspear.equipmentcount; " Degats : " ironspear.equipmentdamage; " Defense : " ironspear.equipmentdefense; " Durabilite : " ironspear.equipmentdurability
_PUTIMAGE (X, Y), ironspearcount&
print ""
_FREEIMAGE ironspearcount&
Else
end if
If stoneaxe.equipmentcount >= 1 THEN
X = (POS(0) - 1) * _FONTWIDTH
Y = (CSRLIN - 1) * _FONTHEIGHT
stoneaxecount& = _LOADIMAGE("stoneaxe.png", 32)
print " Hache en pierre :" stoneaxe.equipmentcount; " Degats : " stoneaxe.equipmentdamage; " Defense : " stoneaxe.equipmentdefense; " Durabilite : " stoneaxe.equipmentdurability
_PUTIMAGE (X, Y), stoneaxecount&
print ""
_FREEIMAGE stoneaxecount&
Else
end if
If copperaxe.equipmentcount >= 1 THEN
X = (POS(0) - 1) * _FONTWIDTH
Y = (CSRLIN - 1) * _FONTHEIGHT
copperaxecount& = _LOADIMAGE("copperaxe.png", 32)
print " Hache en cuivre :" copperaxe.equipmentcount; " Degats : " copperaxe.equipmentdamage; " Defense : " copperaxe.equipmentdefense; " Durabilite : " copperaxe.equipmentdurability
_PUTIMAGE (X, Y), copperaxecount&
print ""
_FREEIMAGE copperaxecount&
Else
end if
If ironaxe.equipmentcount >= 1 THEN
X = (POS(0) - 1) * _FONTWIDTH
Y = (CSRLIN - 1) * _FONTHEIGHT
ironaxecount& = _LOADIMAGE("ironaxe.png", 32)
print " Hache en fer :" ironaxe.equipmentcount; " Degats : " ironaxe.equipmentdamage; " Defense : " ironaxe.equipmentdefense; " Durabilite : " ironaxe.equipmentdurability
_PUTIMAGE (X, Y), ironaxecount&
print ""
_FREEIMAGE ironaxecount&
Else
end if
SLEEP
Now I would like to start with the Equipment screen, I will need to think further on how to proceed properly. I'll share my findings soon.
Thank you in advance!
Posts: 383
Threads: 56
Joined: Apr 2022
Reputation:
13
Steve - I'm not sure how to measure the speed of the method I'm using to calculate the size of an array and then dimension it. I have a number of files with data that are grow in size over time. The method I'm using is to simply count the number of data items in the file and then create the array.
for example
Code: (Select All) t# = Timer(0.001)
count = 0
For c = 1 To limit: count = count + 1: Next
Dim Shared foo(count)
Print Using "There were ###,###,### items in the array, and it took us ##.### seconds to fill it."; UBound(foo), t1# - t#
This is showing no time at all, how would I change the code to get a truer measure of the fill time of what I'm doing and your ReDim examples?
|