View Full Version : Changing vars, BYREF like
One thing that's not immediately clear to me how I can change the content of vars passed as a parameter calling a module defined Sub/Function.
That is, what I want to do is something like:
DIM x, y, r, g, b as LONG
x = 10
y = 15
TBDOG_PGET(x, y, r, g, b)
So in the PB defined sub I want to be able to alter those r, g and b var with the actual pixel values.
I think I have to get the token id while parsing the parameters, but a small example as a guideline will be much appreciated.
Thanks,
Bye!
Petr Schreiber
24-03-2007, 19:33
Hi Mark0,
this can be done very easily, Eros explained it in one post: please read here (http://community.thinbasic.com/index.php?topic=561.msg2824#msg2824)
Good luck with your module !
Bye,
Petr
Perfect! :)
Many thanks,
Bye!
ErosOlmi
24-03-2007, 23:41
Thanks Petr.
Maybe worth to repeat here again.
In case you need variables passed by reference, here it is an little Power Basic example on which functions to use from thinCore.dll interface to be able to change one or more variable passed byref like "dialog get client hWnd to x, y":
'---Declare needed variables. To change a variable we need
'---a reference pointer and an aboslute position (in case of arrays)
LOCAL lVariablePtr1 AS LONG
LOCAL lVariableAbsPos1 AS LONG
LOCAL eResult1 AS EXT
LOCAL lVariablePtr2 AS LONG
LOCAL lVariableAbsPos2 AS LONG
LOCAL eResult2 AS EXT
'---Check if any error
IF thinBasic_ErrorFree THEN
'---Get reference of first variable
thinBasic_VariableParse(lVariablePtr1, lVariableAbsPos1)
'---Check if comma
IF thinBasic_CheckComma() AND thinBasic_ErrorFree THEN
'---Get reference of second variable
thinBasic_VariableParse(lVariablePtr2, lVariableAbsPos2)
IF thinBasic_ErrorFree THEN
'---Here do what you need to do
'---Now assign values to referenced variables
thinBasic_ChangeVariableNumberDirect (lVariablePtr1, lVariableAbsPos1, eResult1)
thinBasic_ChangeVariableNumberDirect (lVariablePtr2, lVariableAbsPos2, eResult2)
END IF
END IF
END IF
ErosOlmi
24-03-2007, 23:42
???
TBDOG...
What's that?
;D
Let's say it's just a code name! :D :D TBDW will probably be a better prefix, yeah! :)
BTW, I'm having some problems getting the thinBasic_VariableParse working.
I have noticed from the thinCore.INC that the parameters have changed, but I'm getting nothing as the var name and 1 for both the other two parameters. I'm surely doing something wrong...
Bye!
I'm surely doing something silly, so I'll appreciate if someone can point out what I'm doing wrong:
Here's the a thinBasic test source:
MODULE "tBDW"
dim res as long
dim u as ext
TBDW_Test(u)
res = Msgbox(0, "U:" & str$(u))
Here's PowerBASIC symbol loading:
thinBasic_LoadSymbol "TBDW_Test", %thinBasic_ReturnNone, CODEPTR(Exec_tBDW_Test ), %thinBasic_ForceOverWrite
And the actual procedure:
SUB Exec_tBDW_Test()
LOCAL VName AS STRING
LOCAL VPTR AS LONG
LOCAL VAbsPos AS LONG
LOCAL myValue AS EXT
IF thinBasic_CheckOpenParens() THEN
thinBasic_VariableParse(VName, VPtr, VAbsPos)
IF thinBasic_CheckCloseParens() THEN
MSGBOX STR$(VPtr) & "," & STR$(VAbsPos) & ", [" & VName$ & "]", , "PowerBASIC"
MyValue = 117
thinBasic_ChangeVariableNumberDirect (VPtr, VAbsPos, MyValue)
END IF
END IF
END SUB
The PB's MSGBOX show VPTR = 1, VAbsPos = 0 and VName as large empty string, and obviously it then GPF ???
Thanks,
Bye!
ErosOlmi
25-03-2007, 07:54
Marco,
the syntax you are using for thinBasic_VariableParse is an old one.
Current one has no VariableName to be passed:
DECLARE FUNCTION thinBasic_VariableParse _
LIB "thinCore.DLL" _
ALIAS "thinBasic_VariableParse" _
( _
BYREF VariablePtr AS LONG , _ '---ATTENTION: parameter passed BYREF will return info
BYREF VariableAbsPos AS LONG _ '---ATTENTION: parameter passed BYREF will return info
) AS LONG
So change your function to
SUB Exec_tBDW_Test
LOCAL VPTR AS LONG
LOCAL VAbsPos AS LONG
LOCAL myValue AS EXT
IF thinBasic_CheckOpenParens( ) THEN
thinBasic_VariableParse(VPtr, VAbsPos) '---<<<<<<<<<Change here. No more var name
IF thinBasic_CheckCloseParens( ) THEN
MSGBOX STR$ (VPtr) & "," & STR$ (VAbsPos) & ", [" & "]", , "PowerBASIC"
MyValue = 117
thinBasic_ChangeVariableNumberDirect (VPtr, VAbsPos, MyValue)
END IF
END IF
END SUB
Just in case, please find attached latest thinCore.inc file interface.
Let me know.
Ciao
Eros
OK, now it work perfectly!
Thanks,
Bye!
Here is the first release.
tBDW - thinBasic Project Dogwaffle scriptable interface (http://mark0.net/plugins-tbdw-e.html)
The API implemented is minimal at the moment, but it's just what's needed to access the pixels and do a variety of filters, for example.
Is there a more appropriate section in the forum to make a post? I looked around but I'm a bit confused about what me the better! :)
Bye!
Michael Hartlef
25-03-2007, 16:07
Thanks for the support of thinBasic. Dogwaffle is a commercial app right?
Yes, Project Dogwaffle Pro is a commercial up.
But there's also a free version, here:
http://www.thebest3d.com/dogwaffle/free/index.html
It's obviously a bit older and limited, but the basic features are there, and tBDW works with it too.
Bye!
Michael Hartlef
25-03-2007, 17:07
Cool, then I can check it out. Thanks for the info.
Petr Schreiber
25-03-2007, 18:04
Hi Mark0,
I have tried your module and it works good !
I think there will be lot of fun experimenting with images :)
Bye,
Petr
Thanks all, for the info & support! :)
TheBest3D already added a link to tBDW, so thinBasic is now mentioned also in ther 3rd-party plugins page:
http://www.thebest3d.com/dogwaffle/3rdpartyplugins/index.html
Bye!
Petr Schreiber
26-03-2007, 20:43
Hi Mark0,
this is nice. It is interesting to watch how innocent formulas can destroy image :D:
MODULE "tBDW"
dim x, y as long
dim r, g, b as long
for y = 0 to %TBDW_HEIGHT - 1
for x = 0 to %TBDW_WIDTH - 1
TBDW_GETRGB(x, y, r, g, b)
r = 128+sin(r/40)*127
g = 128-sin(g/40)*127
b = 128+cos(b/40)*127
TBDW_SETRGB(x, y, r, g, b)
next
TBDW_Progress(y / %TBDW_HEIGHT * 100)
next
Bye,
Petr
Petr Schreiber
27-03-2007, 22:07
Mark0,
just one idea...
When I run the script and DogWaffle is not on it correctly pops up message it should be opened, but then it tries to continue with script.
What about something like TBDW_IsDogWaffleOpen ?
then we could react on this situation in any appropiate way like:
IF TBDW_IsDogWaffleOpen = 0 THEN
MSGBOX (0, "You need to have DogWaffle running, try again")
Stop
END IF
What do you think ?
Petr
I had already added a more meaningful (I hope) message / warning, but a function will probably be better. Thanks for the suggestion!
Bye!
Hi Mark0,
this is nice. It is interesting to watch how innocent formulas can destroy image :D:
Bye,
Petr
Petr how did you use your script? Or did you load a picture and run it thru dogwaffle somehow?
Petr Schreiber
29-03-2007, 08:36
Hi kryton,
you just have to install DogWaffle and make it run.
In this program you will open new image, doesn't matter which size.
Then try to draw something in.
After this you just launch the thinBasic script for example from Windows Explorer or anything else.
Mark0s module will do the work like finding the window and operating the bitmap.
Bye,
Petr
Just uploaded a minor update, ver. 1.02.
http://mark0.net/plugins-tbdw-e.html
Bye!
Hi kryton,you just have to install DogWaffle and make it run.
In this program you will open new image, doesn't matter which size.
Then try to draw something in.After this you just launch the thinBasic script for example from Windows Explorer or anything else.
Mark0s module will do the work like finding the window and operating the bitmap.Bye,Petr
Thanks Petr will try it later tonight.
Thanks for the update Mark0
VEry Very cool. I took a greyscale image I had made a moon for ut2k4. I ran the script and it colorized it like the photoshop poster effect. That is really neat.
Dogwaffle is cool so far, but i haven't found how to get to the particle screen I saw on the main page. Maybe it is not available in the free version. I wanted to test it out to see what it did.
But this is neat, because using Mark0's plugin we have access to drawing now in thinBasic using dogwaffle as drawing engine. So that is really COOL!!!