Page 1 of 1
could someone explain cType to me?
Posted: Tue Feb 28, 2012 11:37 pm
by d.m.holdawayGA2553
just wondering if anyone could point me in the right direction or tell me what it does.
i have managed to generate 3 random shapes but i can only move 1 shape into the hole that i have created when i try to move the other shapes which are generated the same way they dont move and the holes fail to accept them even tho its the same code.
looking around at examples i noticed that cType does something but i cant figure out what
this code came from a lesson on multi touch and allows me to move everything on the screen
Code: Select all
on touchStart pTouchId
# Sent each time a new touch is started
end touchStart
on touchEnd pTouchId
# Sent each time a touch ends
end touchEnd
on touchMove pTouchId, pX, pY
# Sent when any touch moves
set the loc of the target to pX,pY
end touchMove
i create my shape using
Code: Select all
on shapeMake
set the loc of the templateButton to tLoc
put any item of "A,B,C" into pLetter
create button ("shape" & pLetter) in group "shape"
end shapeMake
i noted in another example the sheep herder game it has a line of code
Code: Select all
set the cType of the templateButton to "sheep"
now could i use
Code: Select all
set the cType of the templateButton to "shapeA,shapeB,shapeC"
if anyone could point me in the right direction?
thanks for taking the time to read this post.
Re: could someone explain cType to me?
Posted: Tue Feb 28, 2012 11:46 pm
by Mark
Hi,
cType is a custom property. Maybe there is a setPtop handler called cType and there might also be a getProp handler with that name. If there are no such handlers, read the other scripts and see if they do use cType for anything.
Kind regards,
Mark
Re: could someone explain cType to me?
Posted: Wed Feb 29, 2012 12:31 am
by bn
Hi D.M.,
in the stack sheep herder they use the cType as a custom property.
A custom property is a property that you can assign to any object on the fly. You can use any name you want for the custom property you want as long as it is not a reserved name. You can look at the custom properties in the Properties Inspector -> Properties.
Often people prepend the custom properties with a letter. Many use u like in the uType, here they use c, which is also common. But that just makes the code easier to read but it also avoids collisions with reserved words.
In the game they use it to identify "the target"
Code: Select all
if the cType of the target is "sheep" and sDragging is true then
set the loc of the target to pX, pY
end if
This way you know it is a sheep and act upon that.
You could do the same for your buttons if you want to identify your button. But since you name your buttons you could also look at the last char of the short name of the button.
Shure you could put "a,b,c" into the custom property if you wanted. Actually you can put any datatype into a custom property.
Custom Properties are saved with the stack and are thus persistent. (Although if you create a custom property in a standalone application while it is running it will not be saved since standalone applications can not modify themself. You can create a custom property in a standalone, it will just not be persistent.) If you create a custom property during develoment than the custom property will be persistent with its preset value in a standalone.
Custom properties are very handy indeed as you see in the example for Sheep Herder. You might also want to have a look at the documentation for custom properties.
What Mark mentioned, getProp and setProp, is a whole chapter in the documentation and very powerful but not necessary when dealing with simple custom properties.
Kind regards
Bernd
Re: could someone explain cType to me?
Posted: Fri Mar 02, 2012 6:12 pm
by d.m.holdawayGA2553
Thank you so much for taking the time to reply both posts were very helpful
thanks again
Darren
Re: could someone explain cType to me?
Posted: Fri Mar 02, 2012 8:43 pm
by d.m.holdawayGA2553
i am really close now with this,
Code: Select all
if within(field "shapeA", the loc of the target) and the aType of the target is "shapeA" then
delete the target
i know i need to check for the name but i am unsure
i tried
Code: Select all
if within(field "shapeA", the loc of the target) and the name of the target is button "shapeA" then
delete the target
Re: could someone explain cType to me?
Posted: Fri Mar 02, 2012 9:10 pm
by Mark
Hi...
I don't know what you're trying to do, but in the second line you probably want to use
Code: Select all
and the short name of the btn is "shapeA" then
The name of button "shapeA" returns "button" && quote & "shapeA" & quote while the short name just returns "shapeA".
Kind regards,
Mark
Re: could someone explain cType to me?
Posted: Fri Mar 02, 2012 9:51 pm
by d.m.holdawayGA2553
Mark,
thanks a lot thats perfect i was just unsure on how to check for short names.
thanks again
Re: could someone explain cType to me?
Posted: Sun Mar 04, 2012 7:21 pm
by d.m.holdawayGA2553
after i have randomly created my buttons and name them, what is the best way to change the icon of them?
at the moment i am doing it this way
Code: Select all
put any item of "A,B,C" into pLetter
create button ("shape" & pLetter) in group "shape"
if pLetter = "A" then set the icon of button "shapeA" to "1211"
if pLetter = "B" then set the icon of button "shapeB" to "1275"
if pLetter = "C" then set the icon of button "shapeC" to "1274"
well two questions really.
1, why when i run my code does it not want me to put a END IF on the end of the if statements
2, this does work but after it has generated the buttons a number of times it stops generating the buttons.
thanks again
Re: could someone explain cType to me?
Posted: Sun Mar 04, 2012 8:01 pm
by sturgis
EDIT: Forgot. One liner forms of the if statement don't end in 'end if'. Breaking it into multiple lines requires end if, even if there is only 1 if statement rather than a statement list. Why? um. Don't know. But thats the way it works!
One problem is that you are creating a whole bunch of buttons with the same 3 names. So when you set the icon of button "shapeA" which button are you setting the icon of? There are a couple ways around this particular problem. After creation of the button you can refer to it as "the last button"
So it would be if pLetter = "A" then set the icon of the last button to 1211
Or, since you're using "create" to do this, after the create is done, the variable "it" contains the long id of the control that was just created and you can use that to refer to the button.
Another option might be to pre-set button templates for a, b, and c, then just clone them. That way they can have the icon pre-set and the clone will be set the same way.
You might also look at templatebutton in the dictionary. It lets you pre-set properties for the creation of objects.
So, you could
set the label of the templatebutton to "fred is dead
set the icon of the templatebutton to 1102
set the name of the templatebutton to "FredStatus"
create button
and you will have an Button named fredStatus, labeled fred is dead, with its icon set to image id 1102
d.m.holdawayGA2553 wrote:after i have randomly created my buttons and name them, what is the best way to change the icon of them?
at the moment i am doing it this way
Code: Select all
put any item of "A,B,C" into pLetter
create button ("shape" & pLetter) in group "shape"
if pLetter = "A" then set the icon of button "shapeA" to "1211"
if pLetter = "B" then set the icon of button "shapeB" to "1275"
if pLetter = "C" then set the icon of button "shapeC" to "1274"
well two questions really.
1, why when i run my code does it not want me to put a END IF on the end of the if statements
2, this does work but after it has generated the buttons a number of times it stops generating the buttons.
thanks again
Re: could someone explain cType to me?
Posted: Sun Mar 04, 2012 10:46 pm
by d.m.holdawayGA2553
thank you every so much for the wonderful example and advice.
its been really helpful.