Swap Type.

Blitz3D Forums/Blitz3D Programming/Swap Type.

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Heres a SWAP function to try.
It needs expanding to cover all of your fields:

Type Gems
 Field name$
 Field worth
End Type

Global gem.Gems
Global swap.Gems

gem=New Gems
gem\name="silver" : gem\worth=120
gem=New Gems
gem\name="red" : gem\worth=250
gem=New Gems
gem\name="gold" : gem\worth=170
gem=New Gems
gem\name="ruby" : gem\worth=135

ListGems
Print "Swapping 'red' and 'ruby'"
SwapGems "red","ruby"
ListGems

WaitKey
End

Function ListGems()
 Print ""
 Print "------[START]------"
 For g.Gems=Each Gems
  Print "Name = "+g\name+"       Worth = "+g\worth
 Next
 Print "-------[END]-------"
 Print ""
End Function

; swap 2 gems by name
Function SwapGems(n1$,n2$)
 Local flag=False
 For g1.Gems=Each Gems
  If g1\name=n1$
   For g2.Gems=Each Gems
    If g2\name=n2$
     ; swap the variables of the 2 types
     swap.Gems=New Gems
     swap\name=g1\name : g1\name=g2\name : g2\name=swap\name
     swap\worth=g1\worth : g1\worth=g2\worth : g2\worth=swap\worth
     Delete swap
     flag=True : Exit
    EndIf
   Next
  EndIf
  If flag=True Exit
 Next
End Function