December 04, 2020, 11:12:59 AM

Author Topic: [bb] Easy Changeable Types by Guy Fawkes [ 1+ years ago ]  (Read 681 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Easy Changeable Types by Guy Fawkes [ 1+ years ago ]
« on: June 29, 2017, 12:28:43 AM »
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
  1. Type player
  2.  
  3.         Field name$
  4.         Field age
  5.         Field sex$
  6.  
  7. End Type
  8.  
  9. info.player = Initiate_Type ( )
  10.  
  11. ; Create a new pointer variable of type player
  12. info.player = MyFunction( info.player, "Bill", 36, "Male" )
  13.  
  14.         Locate 0, 0
  15.  
  16.                 Print info
  17. ame$ + " - " + infoage
  18.                 Print
  19.                 Print "Sex: "+infosex$
  20.  
  21.                 Print
  22.  
  23.                 Print "Press any key..."
  24.  
  25.         WaitKey
  26.  
  27.         Cls
  28.  
  29. info.player = MyFunction( info.player, "Rachel", 21, "Female" )
  30.  
  31.         Locate 0, 0
  32.  
  33.                 Print info
  34. ame$ + " - " + infoage
  35.                 Print
  36.                 Print "Sex: "+infosex$
  37.                
  38.                 Print
  39.                
  40.                 Print "Press any key to quit..."
  41.  
  42.         WaitKey
  43.  
  44.         Cls
  45.  
  46. End
  47.  
  48. ; store the returned pointer in it.
  49. ; Note that the 'player' and 'player' pointer variables now both point to the same ~
  50. ; custom type object.
  51.  
  52. Function MyFunction.player( info.player, name$, age%, sex$ )
  53.  
  54.         info
  55. ame$ = name$
  56.         infoage% = age%
  57.         infosex$ = sex$
  58.  
  59.         Return info
  60.  
  61. End Function
  62.  
  63. Function Initiate_Type.player ( )
  64.  
  65.         info.player = New player ; Create a new 'player' custom type object.
  66.        
  67.         Return info
  68.  
  69. 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.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal