Attribute combinations help!

shortwaveshortwave Member Posts: 29
edited March 2013 in Working with GS (Mac)
Hi everyone, I have a problem which I can't seem to figure out. It will probably be really easy for you guys!

Anyway, here is what I have:

10 attributes - all integer but only ever 1 or 0

An actor which displays a different image depending on what all those attributes are... For example 1 0 0 1 0 0 0 1 1 0 would display one image, while 1 1 1 1 1 1 1 1 1 1 would display another.

At the moment I have a rule for each combination of attributes that I need, which basically says:

If attribute 1 = 1
If attribute 2 = 0
If attribute 3 = 1
If attribute.....

Like that for all 10 attributes, and that is repeated for every combination I need an image for.

There must be an easier way of doing this... Maybe a table could help somehow? Or maybe is there a way of creating a new attribute out of all the others like this - 1010101010, then I could just say if newattribute=101010101010 then display image?

Also I've had a problem doing it my way as sometimes it doesn't seem to update, usually if I take away a 1 to make a new combination.

I'd also like to know if theres any way I could save a list of combinations like this and load them up easily, like from a table?


Thanks everyone!

Comments

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited March 2013

    Hi @shortwave Yes, using tables would probably be the way to go. But even then, that'll be a lot of work.... I'll explain how in another post after a question, so I'm sure what you're after: you have 10 attributes which could be 0 or 1; you do realize that the total amount of combinations (i.e between 0000000000 and 1111111111 and including those two) is 1010? >>>> http://www.mathsisfun.com/binary-combinations.html

    In other words you need to show over a thousand different images? Is that what you want to do?

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • shortwaveshortwave Member Posts: 29
    I only need to have an image for about 100 of those combinations luckily! All the rest just need to display a blank image...
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited March 2013

    OK, the following is rough, as a guide but should get you up and running:

    •Make a table with a hundred rows and two columns, the first column showing the 100 possible combinations (to make things slightly easier to see what's going on, make these Text attributes), and the second column, also as text, showing the names of the images.

    With your update problem, you need a counter attribute (up to 10) for each "round".

    I don't know how you want to start off the process, let's say with a go button.

    Rule: When Count =0
    Change attribute start to true

    • I also don't know enough details of your game as to how the 0 or 1 integers are generated, so I'll assume it's in 10 different actors.

    In each of the 10 actors' Rules: ---- assuming this

    When Count< 10 and Start is true
    Change attribute Random to (0,1)
    Change attribute Collector --a text attribute--- to Collector..Random

    When TableCount <100 and TableSearch is false and Count = 10
    Change Attribute TableSearch to true
    Change Attribute TableCount to TableCount+1
    When Collector =tableCellValue(YourTable,TableCount,1)
    Change Attribute scene.Background.ActortoChangepic.Image to tableCellValue(YourTable,TableCount,2)
    Change Attribute Count to 0
    Change attribute Start to false
    Otherwise
    Change Attribute TableSearch to true
    Change Attribute scene.Background.ActortoChangepic.Image to blankimage

    --------

    Rule: When TableSearch is true
    Change Attribute TableSearch to false

    -----this is off the top of my head, so untested, and there might be a few minor hiccups with the logic, but that's roughly what you need. Best of luck.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • SocksSocks London, UK.Member Posts: 12,822
    you do realize that the total amount of combinations (i.e between 0000000000 and 1111111111 and including those two) is 1010?
    10 bit has a range of 1024.

    I think you're mixing up the number 10 (1010 in binary) with the largest 10 bit number (1024).

    [/math pedantry]
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited March 2013
    you do realize that the total amount of combinations (i.e between 0000000000 and 1111111111 and including those two) is 1010?
    10 bit has a range of 1024.

    I think you're mixing up the number 10 (1010 in binary) with the largest 10 bit number (1024).

    [/math pedantry]
    S'allright, Socks; thanks! I must have confused the binary of 10 with 2 to the power of ten.... still over a thousand images tho' but luckily @shortwave is going to be using "only" 100 of the combinations...

    Cheers!

    PS I have a dose of some sort of flu and that's my excuse and I'm sticking too it! (I really have, actually; been feeling really grotty the last three days.... all say "aah, poor thing...." ;-) Been sleeping for most of the days, (as well as at night); feeling hot but cold at the same time.... getting fed up with it now, so got up earlier and pretending I'm OK...

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • shortwaveshortwave Member Posts: 29
    Thank you gyroscope that looks very interesting, I'll try something with that as soon as I get home...

    Just to check, my app is basically ten on and off buttons, which control the attributes, and a display which shows the picture, the display changes as soon as a combination matches one that's saved. Will this work ok the way you suggested, I was only wondering because there is no 'round' or anything like that, just a set of ten separate attributes that are changing independently and a display that changes when a certain combination happens...

    Thanks for helping!
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited March 2013

    Hi, by the sound of it, the above will do what you want... (barring the possible logic hiccups);

    As for the "rounds", there is those, as such, i.e every 10 buttons pressed, you get an image or a blank image...., then presumably start again with another "round"...?

    Just thought, you'll have to add self attribute boolean to each of the actors, to stop them being pressed more than once, so something like

    When Count= 0
    Change attribute button1 to false

    When button1 is false
    When touch is pressed
    Change attribute button1 to true
    ----then all the stuff above

    -------same with all the other buttons, changing the number accordingly.


    Thanks for helping!
    You're welcome; hope it all works out for you. :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited March 2013
    I would import the names of all of your images into a table with the name of each image in a separate row.

    Using a loop, concatenate the rows together to form a master image list:
    Change Attribute game.ImageNameList [text] to game.ImageNameList..tableCellValue(tableName,self.loopCounter,1).."#"

    Either change or constrain the image name you want to display:
    Constrain Attribute game.ImageName [text] to game.attribute1..game.attribute2..gameattribute3 [etc.]

    Then check to see if game.ImageNameList contains game.ImageName and if so, Change Attribute self.Image to game.ImageName.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • SocksSocks London, UK.Member Posts: 12,822
    PS I have a dose of some sort of flu and that's my excuse and I'm sticking too it!
    Ah! Yes, maths flu !
    (I really have, actually; been feeling really grotty the last three days.... all say "aah, poor thing...." ;-)

    Ahh, poor thing. :-& :-& :-& :-&
    Been sleeping for most of the days, (as well as at night); feeling hot but cold at the same time.... getting fed up with it now, so got up earlier and pretending I'm OK...
    Sounds nasty, I hate the hot+cold thing.

    This is something for you to read it bed:

    http://www.tuaw.com/2010/10/15/report-iphone-ipad-glass-crawling-with-bacteria-and-viruses/
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited March 2013
    PS I have a dose of some sort of flu and that's my excuse and I'm sticking too it!
    Ah! Yes, maths flu !
    Ha! you're quick, @Socks! (But then you always have been... ;-)
    (I really have, actually; been feeling really grotty the last three days.... all say "aah, poor thing...." ;-)
    Ahh, poor thing. :-& :-& :-& :-&
    Aaaww, thank you. :) I drank the liquid from a boiled onion + took two extra garlic capsules before another doze a couple of hours ago, and now I've woken up again, I'm actually feeling sort of human again for the first time in 3 days.... still a bit of achey limbs and a hot head though..... see how I feel tomorrow...

    This is something for you to read it bed:

    http://www.tuaw.com/2010/10/15/report-iphone-ipad-glass-crawling-with-bacteria-and-viruses/
    Wow, never realised....should have guessed.... I'm gonna disinfect the iPad and my wife's iPhone first thing tomorrow! (Not certain that's where I got the bug from tho' but you never know!)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • shortwaveshortwave Member Posts: 29
    Thanks guys this has been really helpful! I have been fiddling around with making those loops to search the table but it was refreshing just a little bit too slowly, then tatiang just gave me an idea...

    It's really simple but it works, with just 2 rules...

    First concatenated all 10 attributes into one long text attribute,

    Then constrain self.image to that attribute...

    All I needed to do was rename all the images 1001010101 etc and it works perfectly yay!

    Only problem at the moment is it displays white actor when no image name matches, can't think about how to get round that yet. Unless maybe I put a list of possibilities at the start of the rule... If attribute=0101010101001 bla bla *100 then otherwise blank image at the end?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @shortwave, you can't get around the white box issue. That's why I resorted to tables. Otherwise, it would be simple (as you wrote) to implement the rules.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • shortwaveshortwave Member Posts: 29
    hmmm how about if I set the alpha of object to 0, then made it 1 when displaying image, then made all other buttons reset it to 0?
  • shortwaveshortwave Member Posts: 29
    ah I see that doesnt work because it doesnt know when its displaying a valid image or not...
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited March 2013

    @shortwave Full marks for the other method of course but for the record, part of my rules for you first includes concatenating all 10 attributes into one long text attribute:

    ----the following in each of the 10 buttons----
    When Count< 10 and Start is true
    Change attribute Random to (0,1)
    Change attribute Collector --a text attribute--- to Collector..Random

    this concatenates up to 10 from 10 presses, so Collector (text attribute) has the complete list of 10 0 or 1's.

    >>> Nice shortcut to avoid a second column though, by naming the images as the concatenated variations.... neat! (Kicking myself I didn't think of that, instead of making it unnecessarily complicated...)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • shortwaveshortwave Member Posts: 29
    Hey guys just for reference, it is sorted now, thanks to both of you... It's not perfect because I now have 100 images all named 10101010101010 etc which is a bit confusing. I basically just put a rule at the beginning only allow the constrain when the concatenated attribute (which was your idea gyroscope thank you) match a certain condition. It means I have to type in all 100 combinations into the rule, but no tables and it works instantly... Thanks again
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Nice! Glad you got it working.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited March 2013

    Hi, so you mean to avoid the table completely, in an added Rule, set to Any:
    When Collector =111000000 ------ Collector being the concatenated text attribute
    Collector =111001100
    Collector =101000000 --etc up to 100 of them, a lot of work, but would have still needed to be put into a table...
    Change Attribute self.Image to scene.Collector
    Otherwise
    Change Attribute self.Image to blankimage

    That'd work fine providing your images where all named as the 100 same numbers as names.

    Pleased it's working out for you now.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

Sign In or Register to comment.