Page 1 of 1

Images appearing after certain scores are achieved

Posted: Tue Nov 05, 2013 3:54 pm
by Nico_C_GHS
After achieving a score of 10 points, other images are supposed to appear. However, they do not.


This code is in the field that the score goes into:

Code: Select all

   if  content of me >= 10 then send "start_" to image "broccoli"
   if  content of me >= 10 then send "start_" to image "grapes"
   if  content of me >= 10 then send "start_choco" to image "choco"
   if  content of me >= 50 then send "start_alcohol" to image "alcohol"
   if  content of me >= 100 then send "start_burger" to image "burger"
   if  content of me >= 300 then send "start_needle" to image "needle"
   if  content of me >= 200 then send "start_water" to image "water"
This is the code on the "start_choco" function (all of the images have the same code other than the time variable)

Code: Select all

on start_choco
        wait 2 seconds with messages
   set the vis of target to true
end start_choco

Re: Images appearing after certain scores are achieved

Posted: Tue Nov 05, 2013 5:49 pm
by Klaus
Hi Nico,

wrong syntax -> if content of me = ...
Use either:
-> if the text of me = ...
or just
-> if ME = ...


Best

Klaus

Re: Images appearing after certain scores are achieved

Posted: Thu Nov 21, 2013 3:20 pm
by Nico_C_GHS
Hi Klaus,

I tried using the syntax you recommended and still no further progress in making the images appear after the user gets a specified score. Is there something I've missed?

Code: Select all

if text of me = 20 then send "start_" to image "broccoli"
if  text of me >= 10 then send "start_" to image "grapes"
if  text of me >= 10 then send "start_choco" to image "choco"
if  text of me >= 50 then send "start_alcohol" to image "alcohol"
if  text of me >= 100 then send "start_burger" to image "burger"
if  text of me >= 300 then send "start_needle" to image "needle"
if  text of me >= 200 then send "start_water" to image "water"
That code is literally all that is present on the script for the object. The object this code is attached to is the field within which the score is stored.

Re: Images appearing after certain scores are achieved

Posted: Thu Nov 21, 2013 11:52 pm
by Simon
Hi Nico,
I'm just making a wild guess here but, how are you triggering those if/thens, I think you just have them in the script of the field?
You have to wrap them in something to get them to be triggered. (note: I hear that "on textChanged" does not work when the field is changed by script).
So right after you change the count in the field you call a handler with all your if/then

add 10 to field"count"
updateImage

Then in a card script
on updateImage
if text of field "count" >= 10 then send "start_" to image "grapes"
if text of field "count" >= 10 then send "start_choco" to image "choco"
etc
end updateImage

Did I get that right?

Simon

Re: Images appearing after certain scores are achieved

Posted: Tue Nov 26, 2013 2:49 pm
by Nico_C_GHS
Hi Simon,

This works perfectly! Thank you for the help, I've managed to fix all of the images to appear after the corresponding scores have been achieved.

kind regards,
Nico

Re: Images appearing after certain scores are achieved

Posted: Tue Nov 26, 2013 3:16 pm
by Klaus
Hi Nico,

I would use a SWITCH structure like this:

Code: Select all

...
  ## NEVER access fields more than once, if you want SPEED :-)
  put the text of fld "count" into tContent
  switch tContent
    case >= 300
      send "start_needle" to image "needle"
      break
    case >= 200
      send "start_water" to image "water"
      break      
    case >= 100
      send "start_burger" to image "burger"
      break    
    case >= 50
      send "start_alcohol" to image "alcohol"
      break
    case >= 10
      send "start_" to image "broccoli"
      send "start_" to image "grapes"
      break
  end switch
...
Please note that I started with the HIGHEST number possible!
If you start with the LOWEST number, then you may accidentally send something unwanted!
Example:
...
if tContent >= 10 then do whatever
...
This will also apply if tContent = 50 or 100 or 200 or 300!
Know what I mean? So start with the highest number down to the lowest.


Best

Klaus

Re: Images appearing after certain scores are achieved

Posted: Tue Nov 26, 2013 4:08 pm
by Nico_C_GHS
Hi Klaus,

When I use the code you recommended, it comes back with this message :

"card "playscreen": compilation error at line 19 (Expression: double binary operator) near ">=", char 11"

the exact code that I've use is:

Code: Select all

on updateImage
   put the text of fld HitCount into tContent
   switch tContent
          case >= 300
               send "start_needle" to image "needle"
               break
          case >= 200
               send "start_water" to image "water"
               break      
          case >= 100
               send "start_burger" to image "burger"
               break    
          case >= 50
               send "start_alcohol" to image "alcohol"
               break
          case >= 40
               send "start_choco" to image "choco"
               break
          case >= 20
               send "moveme" to image "broccoli"   
               break
          case >= 10
               send "moveme" to image "grapes"
               break
     end switch
end updateImage

If you can see where I've went wrong then please let me know.

Re: Images appearing after certain scores are achieved

Posted: Tue Nov 26, 2013 4:15 pm
by Klaus
Hi Nico,

sorry, this does work 8)

Code: Select all

on updateImage
   put the text of fld "HitCount" into tContent
   switch
              case tContent >= 300
                     send "start_needle" to image "needle"
                     break
              case tContent >= 200
                     send "start_water" to image "water"
                     break     
              case tContent >= 100
                     send "start_burger" to image "burger"
                     break   
              case tContent >= 50
                     send "start_alcohol" to image "alcohol"
                     break
              case tContent >= 40
                     send "start_choco" to image "choco"
                     break
              case tContent >= 20
                     send "moveme" to image "broccoli"   
                     break
              case tContent >= 10
                     send "moveme" to image "grapes"
                     send "start_choco" to image "choco"
                     break
         end switch
end updateImage
Best

Klaus

Re: Images appearing after certain scores are achieved

Posted: Thu Nov 28, 2013 2:49 pm
by Nico_C_GHS
Hi Klaus,

That set of code works better, thank you for that :) Your input/feedback has been extremely helpful!

All the best,
Nico

Re: Images appearing after certain scores are achieved

Posted: Thu Nov 28, 2013 5:26 pm
by Klaus
At your command, Sire! :D