How do you Delete Arrays?
Blitz3D Forums/Blitz3D Beginners Area/How do you Delete Arrays?
| ||
I using Dim arrays and I would like to know how delete arrays ? |
| ||
You can resize them to one, which is the minimum possible size:Dim foo(100) ;created ... Dim foo(0) ;resized to use less space Since each array is permanently bound to its name - the name can't hold anything else and the array can't be assigned to a variable or passed to a function - there's no real need to delete them: there can only ever be a fixed number of the things. (Incidentally, the other kind of arrays take care of themselves and don't need to be deleted either.) |
| ||
thanks Yasha What I am trying to is when sold a player then I remove the arrays and when come buying player then create new arrays... do you understand what I am trying to do? P.S. I think Type are better of using this even thought I prefer Dim arrays as they are easier to do |
| ||
Maybe... But you can only change the sizes, not actually create or destroy them. In the code above, no matter what you do, there can only be one "foo" array. The problem with this being that if you later decide you want two shops, you'll need to hardcode in a whole new array (and functions that use the global name, since you can't pass it in)... some solution involving objects or even the other kind of arrays would be much easier. How are you storing your shop data between uses? The key to the best solution may lie there (if it's not in an array all the time, does it necessarily need to be in an array at all?). |
| ||
this is a typical moment for a type. You can combine types and arrays. use the tpye for new players use the array for their values: Here Create Arrays and delete it via a PlayerTyp type: Type PlayerTyp Field Values%[100] End Type Dim Player.PlayerTyp(10) Player(0)=New PlayerTyp Player(0)\Values[0]=1 Player(1)=New PlayerTyp Player(1)\Values[0]=2 Print Player(0)\Values[0] Print Player(1)\Values[0] Delete Player(0) With this you have the possibility of using as many Arrays as you need without using a lot of space. When you created the player he has his 'personal' array with 100 elements. after deleting the player, also the array will also be deleted. |
| ||
Hey Yasha and Midimaster Midimaster: I have look at your code and thought there is quick shortcut of doing it by using for loop :) Type PlayerTyp Field Values%[100] End Type Dim Player.PlayerTyp(10) For i=1 To 2 Player(i)=New PlayerTyp Player(i)\Values[i]=i Next For i=1 To 2 Print Player(i)\Values[i] Next Delete Player(0) I think i could my rewrite code and do it in type instead! Yasha: What I am doing at the moment is this Using Dim arrays in begin of the program then I used Repeat Cls Locate 0,10 :Print "TO - TYPE - " Locate 0,30 :Print "Sell/List your players -A" Locate 0,50 :Print "Distlay League Table -T" Locate 0,70 :Print "Board -B" Locate 0,90 :Print "Save Game -S" Locate 0,110:Print "Quit the Game -Q" Locate 50,140:Print "Press Space Bar to Continue" Locate 0,160:Key$=Input("") If Key$="A" Or Key$="a" Pick_Players() EndIf If Key$="T" Or Key$="t" LEAGUE_TABLE() EndIf If Key$="B" Or Key$="b" Board() EndIf If Key$="Q" Or Key$="q" Quit_Game=True EndIf Until Quit_Game=true I still got long way go of finishing it :) Last edited 2012 |