January 20, 2021, 01:20:29 PM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Miscellaneous
»
[bb] Easy Changeable Types by Guy Fawkes [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bb] Easy Changeable Types by Guy Fawkes [ 1+ years ago ] (Read 700 times)
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
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.
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Miscellaneous
»
[bb] Easy Changeable Types by Guy Fawkes [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal