This code has been declared by its author to be Public Domain code.
Download source code | Easy Changeable Types by Guy Fawkes | 2015 |
| |
|
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! |
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\name$ + " - " + info\age
Print
Print "Sex: "+info\sex$
Print
Print "Press any key..."
WaitKey
Cls
info.player = MyFunction( info.player, "Rachel", 21, "Female" )
Locate 0, 0
Print info\name$ + " - " + info\age
Print
Print "Sex: "+info\sex$
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\name$ = name$
info\age% = age%
info\sex$ = 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 |
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.
|
|
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!
|
|
I'll really need to study this one more closely, looks like may help to wrap my head round it.
|
|
Wow! I'm so glad to see this helping alot of people! :) I hope you can make use of it all! :)
|
|
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.info
That might clear it up even more by using something that reads exactly as to what is going on in there.
|
|
What is this code supposed to do ?
|
|
Make learning types easier.
|
Code Archives Forum