This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2007-08-17 11:54:57

paulmedwal
Scratcher
Registered: 2007-03-09
Posts: 100+

Capture the Flag fix

This is made for a specific Scratch user to fix one of their projects.

You need to use an "and" block...lets look at your code

[blocks]
<if> <<( <{ red health }> <<> 70 )>
<switch to costume[ red 75 health
<end>
<if> <<( <{ red health }> <<> 51 )>
<switch to costume[ red 50 health
<end>
<if> <<( <{ red health }> <<> 30 )>
<switch to costume[ red 25 health
<end>
[/blocks]

The problem is that when the red health = 20, all three of the above if statements are true, and the stick figure goes through all of the costumes. To fix it, say

[blocks]
<if> << <( 51 <<> <{ red health }> )> <and> <<( <{ red health }> <<> 70 )> >>
<switch to costume[ red 75 health
<end>
<if> << <( 30 <<> <{ red health }> )> <and> <<( <{ red health }> <<> 51 )> >>
<switch to costume[ red 50 health
<end>
<if> <<( <{ red health }> <<> 30 )>
<switch to costume[ red 25 health
<end>
[/blocks]

Using the "and" block, you can create a range that you want to test. Hope this helps.
Paulmedwal

Last edited by paulmedwal (2007-08-17 12:01:14)


clutter.scratch.mit.edu Visit the Clutter site to create multi-scene stories and multi-level games with Scratch.

Offline

 

#2 2007-08-17 15:53:38

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Capture the Flag fix

Alternatively, if this is not part of a continuos loop, you could simply put them in ascending order (check <30, check <50, check <60) then put a stop command after the first and second costume change.


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#3 2007-08-17 17:14:34

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Capture the Flag fix

[block]
<if> <( red health <<> 30 )>
<switch to costume[ red 25 health
  <else>
     <if> <( red health <<> 51 )>
      <switch to costume[ red 50 health
     <else>
        <if> <( red health <<> 70 )>
         <switch to costume[ red 75 health
       <end>
   <end>
<end>
[/block]

would do only as many tests as needed, and avoids the awkward ands.

Last edited by kevin_karplus (2007-08-17 17:17:00)

Offline

 

#4 2007-08-18 11:32:38

paulmedwal
Scratcher
Registered: 2007-03-09
Posts: 100+

Re: Capture the Flag fix

For the red guy's script...you just need to make the health for both the blue and red guy set to 100.
[blocks]
<when green flag clicked>
<set{ Blue Health }to( 100
<set{ red Health }to( 100
<reset timer>
...
[/blocks]

Do the same for the blue guy.

Paulmedwal


clutter.scratch.mit.edu Visit the Clutter site to create multi-scene stories and multi-level games with Scratch.

Offline

 

#5 2007-08-18 11:52:03

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Capture the Flag fix

If "red health" and "blue health" are both global variables, then each one only needs to be initialized in one <when greenflag clicked> script.

Offline

 

Board footer