Returning a handle instead of manually creating one!

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Returning a handle instead of manually creating one!

Post by LarsG »

Hi,
I just wanted to put what was briefly mentioned here, in this section as well..
It concerns the issue of having PB commands returning a handle, instead of you manually having to create one.
This is, as mp303 mentions, the way most of other programming languages work, but not PB...
And I think that this issue shouldn't be put off (postponed) much longer as, I believe,
it will have to be done sometime, and the longer you wait... (you know ;))

Anyway, I'd like (and I'm sure many others too) some feedback on this, hopefully from Fred as well.. ;)
And I hope I won't be flamed to death.. hehe *LarsG puts on his fireman suit* :p

-Lars

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Returning a handle instead of manually creating one!

Post by PB »

Do you mean "gadget numbers" instead of "handles" ?

If so, I'd prefer to number my gadgets manually with my own descriptive
constants. You can't do that if PureBasic automatically gives a number.
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

No, I mean handles... ie. for entities, images etc..
like:

Code: Select all

hImage = CreateImage(..)
hMyChar = CreateEntity(..)
hCamera1 = CreateCamera(..)
this kind of stuff... :)

-Lars

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

Some people, like me, are preferring handles for about anything instead.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

I don't get it... PureBasic already returns handles for gadgets etc.
For example: ButtonHandle=ButtonGadget(nr,x,y, ...).
What am I misunderstanding?
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

Code: Select all

Syntax
ButtonGadget(#Gadget, x, y, Width, Heigth, Text$ [, Flags]) 

Description
Create a button gadget in the current GadgetList. #Gadget will be the number returned by EventGadgetID() command. 
'Flags' are optionnals and can be composed of one or several of the following constants:
  #PB_Button_Right     : Aligns the button text to right 
  #PB_Button_Left      : Aligns the button text to left 
  #PB_Button_Default   : Makes the button look as the default button of the window 
  #PB_Button_MultiLine : If the text is too long, it will be displayed on several line 
  #PB_Button_Toggle    : Creates a toggle button: one click makes it pushed, another will release it
The #Gadget here would suggest that you must define the gadgetnumber before creating the gadget... wouldn't it?
now what if you would want to create gadgets "on the fly" (runtime)?! then what?

But seriously, I wasn't exactly aiming this at gadgets (buttons etc.), but more towards the things you normally generate during runtime... (ie. images/sprites, entities etc.)

-Lars

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> The #Gadget here would suggest that you must define the gadgetnumber before creating the gadget... wouldn't it?
> now what if you would want to create gadgets "on the fly" (runtime)?! then what?

So, you did mean "gadget numbers" instead of "handles", as I said.
No wonder I was getting confused! Handles <> gadget numbers. :?
I had a similar wish here: viewtopic.php?t=3214
Last edited by PB on Mon Aug 18, 2003 1:31 pm, edited 1 time in total.
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

oh, I thought you meant too use with Gadgets (like buttons)... oops.. my bad.. :oops:
At least now we understand eachother.. 8)

-Lars

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post by Tranquil »

@LarsG:

Its right that in some cases only a handle is more usefull then an ID. But there are some issues you have to think about:

PB should be OS independent. Some other OSs do not use pointers instead of handles.

Fred wants to implement a #PB_Any flag, then an ID is returned instead of a handle. Thats a good way between handles and IDs I think.

Cheers
Mike
Tranquil
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

hmm... I thought a pointer was a handle... oh, well.. ID/pointer/handle, whaterever you call it, as long as PB handles these numbers internally, and that you can get access to the specific object (via pointers/IDs.. it's still just an integer ;))

-Lars

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
Justin
Addict
Addict
Posts: 948
Joined: Sat Apr 26, 2003 2:49 pm

Post by Justin »

Handles are better, no doubt. It is a big lack due to the OS independent thing.
plouf
Enthusiast
Enthusiast
Posts: 281
Joined: Fri Apr 25, 2003 6:35 pm
Location: Athens,Greece

Post by plouf »

AmigaOS,Windows and linux use handles (not 100% sure for linux)
the reason PB use numbers are internal numbering
you can virtually "group" gadgets for example
for example 100 strings in a form can be deactivarted in a loop

for i=firstgadgetnumbet to firstgadgetnumbet+100
disableGadget(i,0)
next

offcourse not all people need this and always we lokking for what makes easiest thinks for NOW
but i agree that handles are usefull for some cases (GadgetID())
anyway i like numbering
but as stated before a Hybrid system is comming (#PB_ALL)
so everybody (?) will be happy ;)
Christos
Kris_a
User
User
Posts: 92
Joined: Sun Feb 15, 2004 8:04 pm
Location: Manchester, UK

Post by Kris_a »

Using a handle would work on all operating systems, surely? It's just a pointer to a location in the system's memory where the object/sprite/whatever is stored.

I agree really strongly with this request. I think being able create stuff on-the-fly without worrying about where it is in a list would be great (especially since, back when I was making an 'Point & Click Adventure studio' in Blitz, I had a type (structure) holding an object's unique image as a handle. This let me make any number of objects each with their own piccy)

Kris
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

A dynamically created unique identifer (whatever it is called) is a good idea. Is that what #PB_Any is (to be)?

How will it work, where would the flag be used?

Creating?
  myDynID=createSomeThing(#Who_Cares,args,#PB_Any)
Referring?
  setSomethingState(myDynID,args,#PB_ANY | #PB_UseUnique)

Is it similar to:

  myDynID+1 : createSomeThing(myDynID,args)

Or would it return actual handles/pointers where possible, and a dynamically created number for an OS where this was not possible?
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

Windows handles are not pointers. You can get 1000, for example, as a handle, which is not a pointer to readable data in Windows. It's more like a Windows internal index, like PureBasic indexes.
El_Choni
Post Reply