Page 1 of 1

Way to make UniqueIDs?

Posted: Mon Nov 11, 2024 2:34 pm
by Bugala
Several of Hollywood commands support UniqueID, like if I put:

Code: Select all

UniqueID = MakeButton(Nil...)
I will get a UniqueID.

However, these seem to be tied to a return value of some certain commands like MakeButton or CreateTextObject as example.

It would be handy to have an option to make these UniqueIDs myself. For example I have this AnimationQueue where there are Timed Animations, as in Animations that last a certain time and are then destroyed from the queue. Destruction of them is based upon each Animation having a Unique name and this way using this name this animation is destroyed.

Sometimes I do want to use a specific name, but often times i just need it to have a unique name to not collide with others and to be destroyed in the end.

I can of course make a system like:

Code: Select all

a=a+1
Name="noname"..a
But I think it would be Handy If I could instead use something like:

Code: Select all

Name=CreateUniqueID()
instead.

But is this doable in Hollywood already, and if not, then as a wishlist item.

Re: Way to make UniqueIDs?

Posted: Tue Nov 12, 2024 8:18 am
by plouf
Hi

Just to understand your point
What the diffirence of that , than using manually enumerated variables, and rhen use than as identifiers?

I.e. if in the beggining you have enumerated

Tempframe =121
Tempframelocal =122

Framebomb= 151
Fframeflower=152


Etc

And use this as numbering. Then destroy frame/brush framebomb, you can then recreate framebomb ?
Correct ?

Howerer i agree with idea, and maybe is a good idea to have something that is more universal in languange it self
For example RandomNonRepeated() ?
This can a retirn a non repeated number for general use /frames or lottery games etc.

Also some other languanges have a preprocessor enumeration for constants, used for similar implementation than your ide

P.s. i am not denied your idea, just thinking the most universal/wide used idea/implementatio

Re: Way to make UniqueIDs?

Posted: Wed Nov 13, 2024 12:00 pm
by Bugala
Idea is that these things are created on the fly.

I have this ActiveAnimations list which has some commands, like ActiveAnimations.Add() which adds to the list a new one, and while being added, It will also create a UniqueID for it, which is used to destroy that animation from the list at a later point, as idea is that these animations have a certain lifespan, like 1 second for example, and This ActiveAnimations has its own Interval function which takes care of both checking if the end of life has been reached, as well as then destroying it from the list.

Re: Way to make UniqueIDs?

Posted: Tue Dec 17, 2024 11:10 am
by Allanon
Some time ago I coded a similar things because I needed temporary & unique names, it's part of my helpers library and here is the code:

Code: Select all

Function HL.GetRndName()
/******************************************************************************
name = HL.GetRndName()

Use this function to obtain a unique random name anytime you need it.
---------------------------------------------------------------------
OUTPUT
  name => A string with an unique random name.
NOTES
  All returned random names are stored in the HL.RandomNames table to avoid 
  reusing and make them unique, if you wish to reset the assigned names for
  some reasons (for example for low memory conditions) just reset this table
  but be aware that already assigned names could be reused.
******************************************************************************/
  Local rnd_name = PadNum(Rnd(999999), 6)
   
  While GetType(RawGet(HL.RndNames, rnd_name)) <> #NIL
    rnd_name = PadNum(Rnd(999999), 6)
  Wend

  HL.RndNames[rnd_name] = 1

  Return("rnd" .. rnd_name)

EndFunction
You only have to define the HL.RndNames[] or use another one, hope this help ;)
This is an old function when IsNil() didn't yet existed, you can replace:

Code: Select all

GetType(RawGet(HL.RndNames, rnd_name)) <> #NIL
with

Code: Select all

IsNil(HL.RndNames, rnd_name)