[bb] Easy Changeable Types by Guy Fawkes [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:43

Previous topic - Next topic

BlitzBot

Title : Easy Changeable Types
Author : Guy Fawkes
Posted : 1+ years ago

Description : This code snippet I made allows you to switch between data easily. GREAT for beginners who get sick of using Dims ( ) or many Global variables!

Code :
Code (blitzbasic) Select
Type player

Field name$
Field age
Field sex$

End Type

info.player = Initiate_Type ( )

; Create a new pointer variable of type player
info.player = MyFunction( info.player, "Bill", 36, "Male" )

Locate 0, 0

Print info
ame$ + " - " + infoage
Print
Print "Sex: "+infosex$

Print

Print "Press any key..."

WaitKey

Cls

info.player = MyFunction( info.player, "Rachel", 21, "Female" )

Locate 0, 0

Print info
ame$ + " - " + infoage
Print
Print "Sex: "+infosex$

Print

Print "Press any key to quit..."

WaitKey

Cls

End

; store the returned pointer in it.
; Note that the 'player' and 'player' pointer variables now both point to the same ~
; custom type object.

Function MyFunction.player( info.player, name$, age%, sex$ )

info
ame$ = name$
infoage% = age%
infosex$ = sex$

Return info

End Function

Function Initiate_Type.player ( )

info.player = New player ; Create a new 'player' custom type object.

Return info

End Function


Comments :


dna(Posted 1+ years ago)

 Thanks for this tutorial.I think it may have finally made the use of pointers stick in my brain. It had previously escaped me for some reason.I'll try this method from now on.


Guy Fawkes(Posted 1+ years ago)

 Glad you could find some use with it! :) Pointers always got to me too. They still do! But they're MUCH easier now thanks to a little research & this function!


Rick Nasher(Posted 1+ years ago)

 I'll really need to study this one more closely, looks like may help to wrap my head round it.


Guy Fawkes(Posted 1+ years ago)

 Wow! I'm so glad to see this helping alot of people! :) I hope you can make use of it all! :)


dna(Posted 1+ years ago)

 hey Guy.What would make this easier to understand would be the use of a non similar type name.Instead of using player.player use player.infoThat might clear it up even more by using something that reads exactly as to what is going on in there.


Guy Fawkes(Posted 1+ years ago)

 Edited.


RemiD(Posted 1+ years ago)

 What is this code supposed to do ?


Guy Fawkes(Posted 1+ years ago)

 Make learning types easier.