survival guide / primer

Developed or developing a new product in PureBasic? Tell the world about it.
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

I see it's for beginners.
I wouldn't start about pointers but i would like to see the BYREF example.

Also applies to the PureBasic helpfile imo, it's hard to remember how byref worked again.

This issue was discussed here once:
viewtopic.php?t=9027

However the solution to pass the pointer makes it actually harder, compare this:

Code: Select all

; same for long 
Procedure SetLong(*p.LONG) 
  *p\l = 15 
EndProcedure 

SetLong(@i) 
Debug i 

With:

Code: Select all

Sub SetLong( p As Long )
    p = 15
End Sub

Dim p As Long
SetLong p
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

made some minor additons to the toc (symbols like ! @ # $ % etc.)

i'll have a look at the byref / byval thing, edwin, but what's exactly the problem? :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

1) The byref thing is hard to find out yourself, so a tutorial worth imo.

2) The example once given by a user looks a bit complicated (much pointer stuff)
Maybe this one can be simplified anyway?
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

mmmm... pure has no byref parameter, everything into a procedure always goes byval, so the only way to do it is byval thus via a pointer...

i know that's not what you would like to hear :-)

Code: Select all

procedure xyz(*a.LONG)
   *a\l = 2
endprocedure

q.l = 1
xyz(@q.l)
i think it's the only way to do it, to be honest: instead of passing the variable value you pass the location of the variable in memory

i make a note of it, and see where the proper place in the primer is to add this

(anybody correct me if i am wrong: there is no byref parameter is there?)
Last edited by blueznl on Fri Jun 04, 2004 8:37 am, edited 1 time in total.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

It's not a big issue to do it like above.
But byref seems to be a forgotten option to pb users.
I don't see much asking (or they must be really clever and found out themselves already :) )

If you add it and make a BYREF remark, we can all find it again later on.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

i think, in general, using vars by ref is not the best thing to do (in general) but i admit that's entirely a personal opinion :-) i prefer by ref icw. structs instead of passing each variable by ref, or use globals

it's a VERY personal decision :-)

i'm adding some byref stuff now
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Searhin
User
User
Posts: 41
Joined: Mon May 26, 2003 10:53 am
Location: Germany

Post by Searhin »

@blueznl

Just read your latest chapter.

Note: in your part on enumeration (ch 4.8) you write the first element would get the number 1, but actually it is 0.

Keep up your great work! :D
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

few changes:

- fixed enumeration starting at 0
- added byref/ byval
- bit larger index
- few small changes here and there
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

- bunch of small fixes
- expanded explanation of numbers / id's / handles / #pb_any
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

updated
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

added stuff on strings and command lines

http://www.xs4all.nl/~bluez/datatalk/pure20.htm
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

little more on sprites
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

This is still awesome :) There is something concerning structures that are not listed in the PB manual that is a limitation to structures. You cannot use a structured member in another structure's member array to grab a value.

Ex:

Code: Select all

Structure strA
  memArray.l[10] ;0 - 9
EndStructure

Structure strREF
  memLocation.l
EndStructure

myREF.strREF
myStruct.strA

X.l
For X = 0 to 9
  myStruct\memArray[X] = (X + 1)
Next

myREF\memLocation = 5
#MEMLOC = 5
X = 5

Debug str(myStruct.memArray[#MEMLOC])  ; This show 6
Debug str(myStruct.memArray[5])  ; This show 6
Debug str(myStruct.memArray[X])  ; This show 6
Debug str(myStruct.memArray[myRef\memLocation])  ; This show 0!!!!
As you can see, you cannot use a structured member to grab a value from another structure's array member ... Really weird. This is with the newest PB w/ all updates.
freak
PureBasic Team
PureBasic Team
Posts: 5941
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

You code is not correct PB syntax and does not compile.
After correcting it, i get the proper output.
quidquid Latine dictum sit altum videtur
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

Sorry about that, I corrected it locally as well. damn, it must only have that issue with sprites grr, I'll have to post a more full filling example.
Post Reply