Page 1 of 1

Self variables to Designer codes.

Posted: Mon Aug 25, 2014 1:45 pm
by Bugala
Suppose I have 10 boxes in my designer project, and I want to keep track of how many times each of them have been clicked.

code would be roughly:

Code: Select all

OnCLick:
boxa=boxa+1
text="Total amount of clicks on box a = "..boxa
Problem is, if i want each of the ten boxes to do the same, I have to write them each their own code with variables boxa, boxb, boxc...

What I would really like is to simply instead of choosing to "Run Code" to choose "Run Program".

And then this Program would have a comman something like:

Selfvariable box

And then it would simply refer to:
box = box+1

And each time I would click on any of these boxes, the program would take care of keeping track of the clicks.

Not only would this save time by not needing to write same code several times, but in addition, if I want to make even a minor change to my code, then i have to do it 10 times now, when instead, I could simply alter the code that contains the self variable command that understands to use its own variable for each object that program is used.

Re: Self variables to Designer codes.

Posted: Mon Aug 25, 2014 10:47 pm
by Bugala
I noticed I had misunderstood something here.

I thought "Run Program" referred to, "run Hollywood program".

Hence, another feature request. possibility to pick "Run Hollywood Program". I know that is basically same thing as "Run Code", but it would be handier picking stuff from list, especially if you decide to use same program in many program.

However, to use same program in many designer products, would really need that "Self Variable" thing implemented, so that for example if i want to keep track of clicks on a button, i could each time just pick that "Run Hollywood Program" code, and it would work wihtout need to do anything else.

EDIT: just realised there is actually possibility in "Run code" to insert code from disk, so this does the trick already, although not as conveniently as "Run Hollywood Program" - would, but then again, i rather not have bloated program for nothing.

But Self Variable request stays.

Re: Self variables to Designer codes.

Posted: Wed Aug 27, 2014 8:00 pm
by airsoftsoftwair
This should already be possible by using the SetObjectData() and GetObjectData() functions to store private data inside the Hollywood layer. E.g. something like this:

Code: Select all

box = GetObjectData(#LAYER, uid$, "box")   ; get current click count from private layer data
box = box + 1
text="Total amount of clicks on box a = "..box
SetObjectData(#LAYER, uid$, "box", box)   ; store updated click count in private layer data
uid$ is the UID of your object (can be configured in the name dialog)

Re: Self variables to Designer codes.

Posted: Wed Aug 27, 2014 8:32 pm
by Bugala
Ah, thanks. That will solve my problem nicely!