Discuss Scratch
- CobramCat
-
Scratcher
68 posts
My Security
I have a project which works well to a point.
Everything, and I mean everything works perfectly until I want a light display! I have a list/array table which holds what I want displayed in lights but I cannot resolve that. See below.
I had posted a prior project to gain some insights, see Topic here.:
My respondents (asivi & drmcw) were of value but advices have not lead to me having a resolution in this case.
The project, in kind, is one I wrote sometime ago under a different format. A copy appears here.
Having the value of those thoughts, my issue is here, Security.
Everything, and I mean everything works perfectly until I want a light display! I have a list/array table which holds what I want displayed in lights but I cannot resolve that. See below.
I had posted a prior project to gain some insights, see Topic here.:
My respondents (asivi & drmcw) were of value but advices have not lead to me having a resolution in this case.
The project, in kind, is one I wrote sometime ago under a different format. A copy appears here.
Having the value of those thoughts, my issue is here, Security.
- Mole_Gaming
-
Scratcher
100+ posts
My Security
My best solution is to use clones.
Clones are pretty cool, they're basically multiple objects you can use to do the same task.
However, if a variable is “for this sprite only,” it will be different for each clone.
Here's how I would do this;
1. Make a sprite that has two costumes; one for off and one for on. Name the costumes “0” and “1” (or whatever numbers you store them as in your list)
2. Make two lists for the x and y positions each light needs to be at
3. Make a FOR THIS SPRITE ONLY variable
4.
Clones are pretty cool, they're basically multiple objects you can use to do the same task.
However, if a variable is “for this sprite only,” it will be different for each clone.
Here's how I would do this;
1. Make a sprite that has two costumes; one for off and one for on. Name the costumes “0” and “1” (or whatever numbers you store them as in your list)
2. Make two lists for the x and y positions each light needs to be at
3. Make a FOR THIS SPRITE ONLY variable
4.
define create clones
set [clone v] to [0] //our "for this sprite only" variable
repeat ()//however many clones you want
change [clone v] by [1]
create clone of [myself v]
end
set [clone v] to [0] //just so the original sprite won't interfere
when I start as a clone
go to x: (item (clone) of [light x positions v] :: list) y: (item (clone) of [light y positions v] :: list)
forever
switch costume to (item (clone) of [light states v] :: list)
end
Last edited by Mole_Gaming (Nov. 5, 2016 13:26:47)
- asivi
-
Scratcher
1000+ posts
My Security
I have a project which works well to a point.I don´t see any list with solutions, also you have a list “MyGlow” being as for this sprite only and i'm not sure if it is what you want.
Everything, and I mean everything works perfectly until I want a light display! I have a list/array table which holds what I want displayed in lights but I cannot resolve that. See below.
I had posted a prior project to gain some insights, see Topic here.:
My respondents (asivi & drmcw) were of value but advices have not lead to me having a resolution in this case.
The project, in kind, is one I wrote sometime ago under a different format. A copy appears here.
Having the value of those thoughts, my issue is here, Security.
- CobramCat
-
Scratcher
68 posts
My Security
Firstly, @ Mole_Gaming: Thank you for your scripting thoughts. I shall attempt to incorporate those ideas.
@ asivi, yes you are right about MyGlow, I don't know if I need it or not; looking at Mole_Gaming's thought I should not.
As to a list of solutions? I have not yet programmed for them but I do have then written into a comment on the Stage Script page.
@ asivi, yes you are right about MyGlow, I don't know if I need it or not; looking at Mole_Gaming's thought I should not.
As to a list of solutions? I have not yet programmed for them but I do have then written into a comment on the Stage Script page.
- CobramCat
-
Scratcher
68 posts
My Security
My best solution is to use clones.In reading this again I am wondering if my scripts were ever studied.
Clones are pretty cool, they're basically multiple objects you can use to do the same task.
However, if a variable is “for this sprite only,” it will be different for each clone.
Here's how I would do this;
1. Make a sprite that has two costumes; one for off and one for on. Name the costumes “0” and “1” (or whatever numbers you store them as in your list)
2. Make two lists for the x and y positions each light needs to be at
3. Make a FOR THIS SPRITE ONLY variable
4.define create clones
set [clone v] to [0] //our "for this sprite only" variable
repeat ()//however many clones you want
change [clone v] by [1]
create clone of [myself v]
end
set [clone v] to [0] //just so the original sprite won't interfere
when I start as a clone
go to x: (item (clone) of [light x positions v] :: list) y: (item (clone) of [light y positions v] :: list)
forever
switch costume to (item (clone) of [light states v] :: list)
end
I had created clones of my lights and referenced them by their costume name (they still exist within the body of the project)
In a rewrite I have placed my Off and On lights at positions 1 and 2 of the sprite, and
I have created a Light X and Light Y list to hold the co-ords of the lights; they are read into the lists when the Light panel is created.
I have set variable “LightNo” to For This Sprite Only. I also have a global variable MyID that can be at the Lights page.
Ok, LightOn is local, but as I need to indentify the Light to be toggled from outside this page, MyID is employed. I then let LightOn see MyID by using
set [LightOn] to [MyID]; it matters nought whether I use LightOn or MyID to reference the Light X and Light Y lists.
The
when I receive [ flip]construct still exists on the Lights Page but has been disconnected.
When I attempt to use the “When I start as a clone” construct as given my light panel is wiped out but for one lamp at position 8.
The same thing happens when I press a switch to
broadcast [ flip]
I am rather much in the same position as when I first asked for assistance; but, yes, the advent of two co-ord lists has solved a problem which I was going to have to address when I needed to toggle my lights.
I believe everything is in place to utilise a script which would properly toggle the on/off states of the lamps.
After that is resolved I shall attend to the solutions about which asivi asked.
asivi, 4,9, 12 will yield one immediate solution, ie, will fill the LightOn list with 1's.
Last edited by CobramCat (Nov. 6, 2016 07:52:06)
- Mole_Gaming
-
Scratcher
100+ posts
My Security
In reading this again I am wondering if my scripts were ever studied.Sorry, they were not. I was on my Kindle at the time, which does not support flash. I just stated my solution to the problem.
I will look at your code again and try to figure out whats wrong with your code specifically
- CobramCat
-
Scratcher
68 posts
My Security
It is three days and still I am stuck.
Back on my own computer I am attempting to resolve how to present a “player's” solution on screen when solved.
Back on my own computer I am attempting to resolve how to present a “player's” solution on screen when solved.
- asivi
-
Scratcher
1000+ posts
My Security
Hi, i would like to help you but acually i don't know how it must be working.
Does it matter the order in which you press a switch? Are you going to give some clue?
All i can say you is to create a list with lights sequences and a variable where to add the pressed switchers and then check the variable string against the list.
Does it matter the order in which you press a switch? Are you going to give some clue?
All i can say you is to create a list with lights sequences and a variable where to add the pressed switchers and then check the variable string against the list.
- CobramCat
-
Scratcher
68 posts
My Security
Hi, i would like to help you but acually i don't know how it must be working.Firstly the order of switches does not matter.
Does it matter the order in which you press a switch? Are you going to give some clue?
All i can say you is to create a list with lights sequences and a variable where to add the pressed switchers and then check the variable string against the list.
Secondly each switch controls one or more lights as shown in the table (unfortunately the Tags are not letting me share the Imageshack location):
Light Number
1 2 3 4 5 6 7 8
1 1
2 1
3 1 1
4 1 1 1
5 1 1 1
6 1
7 1 1
8 1 1
9 1 1
10 1 1 1
11 1 1
12 1 1 1
The “LightOn” list indicates that a light is Off if its item is “0”, otherwise the numeral indicates how many switches are actually affecting the light at that time.
All of that is well taken care.
My bother is that I cannot properly address a specific item in “LightOn” and cause the appropriate light to change costume when needed.
I have tried various means to get around this but it always seems that the parent sprite gets addressed, wipes out the display panel and leaves just one image!
I believe that I have actually done much as your final sentence instructs.
Under other programming languages which I have used (Pascal, C, QBasic, javascript) things were never as complicated as this is becoming.
Is there some means to refer such an issue to the Scratch Team? I mean, have lists been incorporated with only one sprite in mind, not viewing a wider context?
- HoofEMP
-
Scratcher
100+ posts
My Security
Clones can't respond to broadcasts, if that's what you mean. Only the parent will respond to any other hats.Hi, i would like to help you but acually i don't know how it must be working.Firstly the order of switches does not matter.
Does it matter the order in which you press a switch? Are you going to give some clue?
All i can say you is to create a list with lights sequences and a variable where to add the pressed switchers and then check the variable string against the list.
Secondly each switch controls one or more lights as shown in the table (unfortunately the Tags are not letting me share the Imageshack location):
Light Number
1 2 3 4 5 6 7 8
1 1
2 1
3 1 1
4 1 1 1
5 1 1 1
6 1
7 1 1
8 1 1
9 1 1
10 1 1 1
11 1 1
12 1 1 1
The “LightOn” list indicates that a light is Off if its item is “0”, otherwise the numeral indicates how many switches are actually affecting the light at that time.
All of that is well taken care.
My bother is that I cannot properly address a specific item in “LightOn” and cause the appropriate light to change costume when needed.
I have tried various means to get around this but it always seems that the parent sprite gets addressed, wipes out the display panel and leaves just one image!
I believe that I have actually done much as your final sentence instructs.
Under other programming languages which I have used (Pascal, C, QBasic, javascript) things were never as complicated as this is becoming.
Is there some means to refer such an issue to the Scratch Team? I mean, have lists been incorporated with only one sprite in mind, not viewing a wider context?
- CobramCat
-
Scratcher
68 posts
My Security
Ok …..
I am using:
So, …. my task then is to activate the second sprite to recognise that the properties of one of its clones has changed, and act upon only that change.
Hmm! Someone did a remix of one of my projects which involved changing costumes (I thought that I was following that mechanism, I'll take a relook) and it does appear to be as asivi was suggesting; I'll study that more closely.
Thanks.
I am using:
when this sprite clickedThose red blocks allow me to influence values for the clone as well as clones of a different sprite.
if <(costume #) = ["x"]> then
....
....
end
So, …. my task then is to activate the second sprite to recognise that the properties of one of its clones has changed, and act upon only that change.
Hmm! Someone did a remix of one of my projects which involved changing costumes (I thought that I was following that mechanism, I'll take a relook) and it does appear to be as asivi was suggesting; I'll study that more closely.
Thanks.
- asivi
-
Scratcher
1000+ posts
My Security
Hi, i've made my own version where right digits' order matters.
I hope this can be inspire you. https://scratch.mit.edu/projects/130229736/
I hope this can be inspire you. https://scratch.mit.edu/projects/130229736/
- CobramCat
-
Scratcher
68 posts
My Security
Ok …..
I see what you have done…
…. but (?) …. I'm unsure if it helps.
In reviewing my Disco Tiles series, where button presses do not matter (well they do to get a correct result), I note that the broadcast mechanism relates to one sprite specifically, has two costumes and just one list.
This project does need multiple lists for transactions to occur.
My prior programming background suggests that I have two identities for this case, switches and lights, which seems to be the simplest scenario.
That brings me to try to understand how I can retain my list structure and yet run my switches (12 costumes currently fine) and lights (2 costumes currently fine - until costume change) under the “umbrella” of just one sprite.
Irregardless of whether that concept will work for me, I'd still like to understand if Child(x) of Parent1 can have an influence, and how, upon Child(y) of Parent2 as I am currently trying. That's a question to which I can find no answer; nothing in Forums nor in any published projects.
I see what you have done…
…. but (?) …. I'm unsure if it helps.
In reviewing my Disco Tiles series, where button presses do not matter (well they do to get a correct result), I note that the broadcast mechanism relates to one sprite specifically, has two costumes and just one list.
This project does need multiple lists for transactions to occur.
My prior programming background suggests that I have two identities for this case, switches and lights, which seems to be the simplest scenario.
That brings me to try to understand how I can retain my list structure and yet run my switches (12 costumes currently fine) and lights (2 costumes currently fine - until costume change) under the “umbrella” of just one sprite.
Irregardless of whether that concept will work for me, I'd still like to understand if Child(x) of Parent1 can have an influence, and how, upon Child(y) of Parent2 as I am currently trying. That's a question to which I can find no answer; nothing in Forums nor in any published projects.
- asivi
-
Scratcher
1000+ posts
My Security
@CobramCat
Sorry if i can't help you, i'm unable to understand what your last post means.
Sorry if i can't help you, i'm unable to understand what your last post means.
- CobramCat
-
Scratcher
68 posts
My Security
@ asivi
Hmmm!
I'm about to readdress my thoughts re having switches and lights having the same sprite; that looks like a mammoth project, but thanks anyway for your attempts.
But then my last post? Which one? I presume that it is about the “double negative” comment?
I misused the word (“irregardless” followed by “whether” ….).
In rereading I should have said “regardless”!
That person's comment was totally unhelpful, it was both pedantic and does, as now, disrupt a reader's focus.
(Um? I have been a moderator elsewhere - one had to attempt to understand ‘corrupt’ English - and so would not have taken exception to poor grammar)
Hmmm!
I'm about to readdress my thoughts re having switches and lights having the same sprite; that looks like a mammoth project, but thanks anyway for your attempts.
But then my last post? Which one? I presume that it is about the “double negative” comment?
I misused the word (“irregardless” followed by “whether” ….).
In rereading I should have said “regardless”!
I have not tried the alternative yetin that exchange was intended to refer to how I might adapt your suggestion.
That person's comment was totally unhelpful, it was both pedantic and does, as now, disrupt a reader's focus.
(Um? I have been a moderator elsewhere - one had to attempt to understand ‘corrupt’ English - and so would not have taken exception to poor grammar)
- asivi
-
Scratcher
1000+ posts
My Security
Sorry again, i was talking about:
Greets.
Ok …..Just to say that it isn't your fault but mine.
I see what you have done…
…. but (?) …. I'm unsure if it helps.
In reviewing my Disco Tiles series, where button presses do not matter (well they do to get a correct result), I note that the broadcast mechanism relates to one sprite specifically, has two costumes and just one list.
This project does need multiple lists for transactions to occur.
My prior programming background suggests that I have two identities for this case, switches and lights, which seems to be the simplest scenario.
That brings me to try to understand how I can retain my list structure and yet run my switches (12 costumes currently fine) and lights (2 costumes currently fine - until costume change) under the “umbrella” of just one sprite.
Irregardless of whether that concept will work for me, I'd still like to understand if Child(x) of Parent1 can have an influence, and how, upon Child(y) of Parent2 as I am currently trying. That's a question to which I can find no answer; nothing in Forums nor in any published projects.
Greets.
- asivi
-
Scratcher
1000+ posts
My Security
https://scratch.mit.edu/discuss/topic/225480
Edit: I've posted this because it could be helpful for others having same issue
REedit. also in the project i've linked before you can see both methods, “BulbID” variable and (costume #) reporter.
Hi, yes, any sprite (including clones) can broadcast a message to any other, for clones firstly create a local variable that you must set to the identifier of a clone if it is the case, or referring an exclusive feature in the receiver clone, for an example its costume.set [message for clone v] to [1]//global variableIn the receiver Sprite
broadcast [message for clone v]when I receive [message for clone v]//l"identifier of clone" must be a local variable
if <(Identifier of clone)= (message for clone)> then
...Whatever...::grey
end
Edit: I've posted this because it could be helpful for others having same issue
REedit. also in the project i've linked before you can see both methods, “BulbID” variable and (costume #) reporter.
Last edited by asivi (Nov. 11, 2016 11:13:15)
- CobramCat
-
Scratcher
68 posts
My Security
https://scratch.mit.edu/discuss/topic/225480Thank you for this and your comments in the other forum threads.Hi, yes, any sprite (including clones) can broadcast a message to any other, for clones firstly create a local variable that you must set to the identifier of a clone if it is the case, or referring an exclusive feature in the receiver clone, for an example its costume.set [message for clone v] to [1]//global variableIn the receiver Sprite
broadcast [message for clone v]when I receive [message for clone v]//l"identifier of clone" must be a local variable
if <(Identifier of clone)= (message for clone)> then
...Whatever...::grey
end
Edit: I've posted this because it could be helpful for others having same issue
REedit. also in the project i've linked before you can see both methods, “BulbID” variable and (costume #) reporter.
At this point I have begun to “strip” my project to focus only upon the logic that I require. At the moment I think that I may need further insight. I'll advise when I have my “mini-project” to my best satisfaction.
Thank you
- CobramCat
-
Scratcher
68 posts
My Security
Ok, I've stripped my project down to SecurityMore.
I believe that I have followed what was advised but there are still issues. I have detailed those in the project notes.
I have tried a few different workarounds and am still finding this very messy/awkward; this is NOT as straightforward as I would have expected.
I believe that I have followed what was advised but there are still issues. I have detailed those in the project notes.
I have tried a few different workarounds and am still finding this very messy/awkward; this is NOT as straightforward as I would have expected.
Last edited by CobramCat (Nov. 13, 2016 01:19:37)
- DadOfMrLog
-
Scratcher
1000+ posts
My Security
@CobramCat:
Sorry, I'm coming to this rather late… I've tried to read through above and I'm still not sure I'm clear on what you actually want to do.
Is it just to make a specific set of lights toggle on/off when a specific switch is switched? (So, for example, if you hit switch 3 then lights 1, 4 & 10 will switch their state.)
If that is all, then it seems very straightforward, and I don't understand why it's proving so difficult.
Or is there something else you want that I haven't quite understood?
BTW, I should just make a clear response to this, in case it causes confusion at some point…
That's also true for all other event hat blocks – clones will run ‘when key pressed’, ‘when clicked’ (if it is the object that was clicked), ‘when timer/loudness’, ‘when backdrop switches’. The only hat block script a clone cannot run is ‘when green flag clicked’, and that's simply because there are no clones at the point a project starts up.
If you want a specific clone to run a broadcast receiver script, then there has to be some way to ‘target’ that clone (perhaps through its costume, or a local ‘this sprite only’ variable that is different for different clones and the original sprite).
Sorry, I'm coming to this rather late… I've tried to read through above and I'm still not sure I'm clear on what you actually want to do.
Is it just to make a specific set of lights toggle on/off when a specific switch is switched? (So, for example, if you hit switch 3 then lights 1, 4 & 10 will switch their state.)
If that is all, then it seems very straightforward, and I don't understand why it's proving so difficult.
Or is there something else you want that I haven't quite understood?
BTW, I should just make a clear response to this, in case it causes confusion at some point…
Clones can't respond to broadcasts, if that's what you mean. Only the parent will respond to any other hats.If a sprite responds to a broadcast then so do all of it clones.
That's also true for all other event hat blocks – clones will run ‘when key pressed’, ‘when clicked’ (if it is the object that was clicked), ‘when timer/loudness’, ‘when backdrop switches’. The only hat block script a clone cannot run is ‘when green flag clicked’, and that's simply because there are no clones at the point a project starts up.
If you want a specific clone to run a broadcast receiver script, then there has to be some way to ‘target’ that clone (perhaps through its costume, or a local ‘this sprite only’ variable that is different for different clones and the original sprite).
Last edited by DadOfMrLog (Nov. 13, 2016 16:06:11)