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

#1 2010-05-25 15:53:47

Jcater
Scratcher
Registered: 2009-11-14
Posts: 13

repeat using a local variable

Hi

wonder if any of u out there can help me

Im struggling to use a variable power and repeat a script to move up or down that number of times


the POWER var is calulated by how long the space bar is held in

for example :
   set POWER = 0
      forever(if(space pressed)
              {
             change POWER by 0.25
              }

the repeat script im failing with is below :


Repeat (round(POWER))
{
change Y by -5
}
Repeat Until ( Y > 50)
{
change Y by 5
}

appreciate any suggestions


Cheers

Offline

 

#2 2010-05-25 16:43:03

fullmoon
Retired Community Moderator
Registered: 2007-06-04
Posts: 1000+

Re: repeat using a local variable

If you're using a "forever" block then you can't put anything below it! How does Scratch know when to execute the second script?


http://i302.photobucket.com/albums/nn100/fullmoon32/wow.jpg

Offline

 

#3 2010-05-25 18:53:30

Jcater
Scratcher
Registered: 2009-11-14
Posts: 13

Re: repeat using a local variable

i only used the forever block for the If otherwise the if statement reguarding the space key press would not function

i understand what your suggesting is wrong but i stil dont kno how to solve the problem :S il keep at it  big_smile  thanks fullmoon

Offline

 

#4 2010-05-25 19:02:04

coka
Scratcher
Registered: 2007-11-03
Posts: 1000+

Re: repeat using a local variable

Jcater wrote:

i only used the forever block for the If otherwise the if statement reguarding the space key press would not function

i understand what your suggesting is wrong but i stil dont kno how to solve the problem :S il keep at it  big_smile  thanks fullmoon

Can you explain in a little more detail of what you want the sprite to do. I can maybe help.  wink


http://i42.tinypic.com/2rot8c2.png

Offline

 

#5 2010-05-25 19:12:27

Jcater
Scratcher
Registered: 2009-11-14
Posts: 13

Re: repeat using a local variable

<a href='http://scratch.mit.edu/projects/Jcater/1075423'><img src='http://scratch.mit.edu/static/projects/Jcater/1075423_med.png' width='425' height='319' alt='Scratch Project'></a> heres the project - very untidy and not functioning due to the repeat problem

Offline

 

#6 2010-05-25 19:15:17

Jcater
Scratcher
Registered: 2009-11-14
Posts: 13

Re: repeat using a local variable

thanks mate - im trying to make a sort of grabber game where your objectives are to get treasure to buy various material

main issue is the grabber itself i would like it to respond to the "power" variable :  the amount of power generated by holding the space bar down

thanks much

Offline

 

#7 2010-05-25 19:16:52

coka
Scratcher
Registered: 2007-11-03
Posts: 1000+

Re: repeat using a local variable

Jcater wrote:

thanks mate - im trying to make a sort of grabber game where your objectives are to get treasure to buy various material

main issue is the grabber itself i would like it to respond to the "power" variable :  the amount of power generated by holding the space bar down

thanks much

So you want the grabber to run faster if the power variable number is higher? Or do you want it to grab (variable power) times


http://i42.tinypic.com/2rot8c2.png

Offline

 

#8 2010-05-25 19:22:14

Jcater
Scratcher
Registered: 2009-11-14
Posts: 13

Re: repeat using a local variable

yea i was hoping that the amount of power would determine how many times to loop around the script for making the grabber fall down then once the repeat loop exits it continues and brings the grabber back up to the ship

seems impossible to do it without a forever loop :S i may have chosen a not very nice method of doing this lol

thanks for the help btw

Offline

 

#9 2010-05-25 19:23:28

Jcater
Scratcher
Registered: 2009-11-14
Posts: 13

Re: repeat using a local variable

did tht help any ??

Offline

 

#10 2010-05-25 19:27:13

coka
Scratcher
Registered: 2007-11-03
Posts: 1000+

Re: repeat using a local variable

Jcater wrote:

yea i was hoping that the amount of power would determine how many times to loop around the script for making the grabber fall down then once the repeat loop exits it continues and brings the grabber back up to the ship

seems impossible to do it without a forever loop :S i may have chosen a not very nice method of doing this lol

thanks for the help btw

Okay I think i get what you mean. I think you are approaching this way harder that needed. I'll work with it a little bit and see if I can figure something out!  wink


http://i42.tinypic.com/2rot8c2.png

Offline

 

#11 2010-05-25 19:36:38

Jcater
Scratcher
Registered: 2009-11-14
Posts: 13

Re: repeat using a local variable

aw cheers mate - al give u a mention on the notes for helpin  big_smile

donno if u ever played mario party mini game just like it - i'm hoping to make it into a sort of rpg similar to that mini game

oh n a noticed on ma script for taking the grabber up the y values should b negitive not positive - god so much mistake lol

Offline

 

#12 2010-05-25 19:38:45

coka
Scratcher
Registered: 2007-11-03
Posts: 1000+

Re: repeat using a local variable

http://i50.tinypic.com/2agvotv.gif
Hope this helps. All you have to do is change the x and y numbers, and you can change the speed. If you need anymore help, I can try to help!  wink  Hope this helps!


http://i42.tinypic.com/2rot8c2.png

Offline

 

#13 2010-05-25 19:43:44

Jcater
Scratcher
Registered: 2009-11-14
Posts: 13

Re: repeat using a local variable

aww cheers mate yeah i see how it wud work fantastic !  big_smile
actually a lot btter controlling in seconds as well
cheers saved many hours of frustration there hahaal go try tht now

Offline

 

#14 2010-05-25 19:45:37

coka
Scratcher
Registered: 2007-11-03
Posts: 1000+

Re: repeat using a local variable

Jcater wrote:

aww cheers mate yeah i see how it wud work fantastic !  big_smile
actually a lot btter controlling in seconds as well
cheers saved many hours of frustration there hahaal go try tht now

Any time!  wink  If you need help just ask, I'll be glad to help!


http://i42.tinypic.com/2rot8c2.png

Offline

 

#15 2010-05-25 19:53:22

Jcater
Scratcher
Registered: 2009-11-14
Posts: 13

Re: repeat using a local variable

Great thanks again heres what Ive got so far

now gonny start on making it a playble game
http://scratch.mit.edu/projects/Jcater/1075423

Offline

 

#16 2010-05-25 20:47:15

coka
Scratcher
Registered: 2007-11-03
Posts: 1000+

Re: repeat using a local variable

Jcater wrote:

Great thanks again heres what Ive got so far

now gonny start on making it a playble game
http://scratch.mit.edu/projects/Jcater/1075423

The effects are great, and the final project will be great, but I think instead of all of what you did, you could do this.

Instead of this,
http://i46.tinypic.com/2r5gt3a.gif

Do this,
http://i48.tinypic.com/54ve5e.gif

You may have to make the grabber stop when it hits something
Hope you like this better!


http://i42.tinypic.com/2rot8c2.png

Offline

 

Board footer