Page 3 of 3
Posted: Fri May 14, 2004 12:11 pm
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
Posted: Fri May 14, 2004 12:39 pm
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?

Posted: Fri May 14, 2004 2:37 pm
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?
Posted: Fri May 14, 2004 4:23 pm
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?)
Posted: Fri May 14, 2004 4:42 pm
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.
Posted: Fri May 14, 2004 5:44 pm
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
Posted: Sun May 16, 2004 9:39 am
by Searhin
@blueznl
Just read your latest chapter.
Note: in your part on enumeration (ch 4.

you write the first element would get the number 1, but actually it is 0.
Keep up your great work!

Posted: Sun May 16, 2004 6:05 pm
by blueznl
few changes:
- fixed enumeration starting at 0
- added byref/ byval
- bit larger index
- few small changes here and there
Posted: Fri Jun 04, 2004 8:34 am
by blueznl
- bunch of small fixes
- expanded explanation of numbers / id's / handles / #pb_any
Posted: Sun Jun 13, 2004 10:57 am
by blueznl
updated
Posted: Tue Jun 15, 2004 11:31 pm
by blueznl
Posted: Sun Mar 06, 2005 10:43 am
by blueznl
little more on sprites
Posted: Fri Apr 29, 2005 1:56 am
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.
Posted: Fri Apr 29, 2005 2:12 am
by freak
You code is not correct PB syntax and does not compile.
After correcting it, i get the proper output.
Posted: Fri Apr 29, 2005 3:36 am
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.