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

#1 2013-01-16 14:10:43

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Please help... Having trouble with a bit of code.

Hi,

This is the code I'm trying to get to work:

Sprite: multiplier
  Costumes (2):
    purple_ (34x18)
    inverted_Purple (34x18)
  Sounds (0):
  Stacks (7):
    when I receive "multiplier_Clicked"
        forever  
            forever  
                if (mouse down?) 
                    if (touching s[mouse-pointer]?) 
                        set "Score" to ((Score) * 2)
                        glide 1 secs to x: 0 y: 0
                        if ((size) < "200") 
                            forever  
                                change size by 5
                                wait 0.01 secs
                                if ((size) = "200") 
                                    hide
                                    set size to 100%
                                    stop script
    end

    when I receive "LVL2_Start"
        wait 1 secs
        go to x: -119 y: 185
        show
        if ((mouse down?) and (touching s[mouse-pointer]?)) else 
            broadcast "multiplier_Clicked"
        else
            glide 1 secs to x: 0 y: 0
            glide 1 secs to x: -242 y: -50
            hide
    end

    when I receive "lvl3_Start"
        go to x: 0 y: 0
    end

    when green flag clicked
        set size to 100%
        hide
    end

    when green flag clicked
        forever  
            next costume
            wait 0.01 secs
    end

    show

    hide
--------

It's for a multiplier that flies across the screen in an FPS(First Person Shooter).

Any help appreciated,


regards,

CAA14

P.S. The blocks may not turn out... I'm not real sure how to do them...

Offline

 

#2 2013-01-16 14:16:54

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: Please help... Having trouble with a bit of code.

Edit: The Show/ Hide on the bottom is not a part of the code... i use it for short hand while programing....

And i believe i forgot to tell you what i want it to do when clicked! (oops)

What i want it to do is stay on the course i tell it to until clicked, then, if clicked i want it to go to x:0 y:0 and get to 200% in size and then disappear.

I hope that clarified things...

regards,


CAA14

Offline

 

#3 2013-01-16 14:18:38

disney22girl
Scratcher
Registered: 2012-09-08
Posts: 100+

Re: Please help... Having trouble with a bit of code.

I'm sorry I don't understand what your talking about I never did that kinda stuff


When you wanna see my sexy just ask  smile

Offline

 

#4 2013-01-16 14:26:37

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: Please help... Having trouble with a bit of code.

Hi,

Thanks for responding,

No problem, it is complicated believe me!  smile


regards,

CAA14

Offline

 

#5 2013-01-17 20:56:09

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: Please help... Having trouble with a bit of code.

Okay, maybe i can clear this up by instead of posting code(Which I'm still new at:)), I'll type a certain goal.


The Goal:


What i want it to have this sprite called "multiplier" appear once it receives a message that a certain level(for example, level 1) and start going to certain x/y coordinates.

But, IF it is clicked, i want it to stop, play a sound, and go to 0,0 and get 200% bigger, then disappear.(Of course, I want it to multiply "score" by 2).

I have both of these things in script, but it skips the second half.

I know it's probably a simple bug, as all programmers make bugs, but i really need to know before i release the project.  smile


regards,

CAA14

Offline

 

#6 2013-01-17 20:59:13

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: Please help... Having trouble with a bit of code.

Edit to original post:

The block of code isn't displaying right, Please disregard it.

regards,

CAA14

Offline

 

#7 2013-01-17 21:07:08

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Please help... Having trouble with a bit of code.

When do you need help by?

Edit: Just to say, you can always report a post to be edited if sommething needs to be changed.

Anyway, hello CAA14 and welcome to Scratch! I wish you momorable, great times here!

Last edited by ErnieParke (2013-01-17 21:36:05)


http://i46.tinypic.com/35ismmc.png

Offline

 

#8 2013-01-17 21:18:04

Wes64
Scratcher
Registered: 2011-08-19
Posts: 1000+

Re: Please help... Having trouble with a bit of code.

this is why new scratchers should be able to edit their posts


Experienced 2.0 Tester: Ask me questions!
Using Firefox 13.0, Flash plugin version 11.4.402.287, and Windows XP Professional.

Offline

 

#9 2013-01-18 11:13:31

sonicfan12p
Scratcher
Registered: 2011-11-16
Posts: 1000+

Re: Please help... Having trouble with a bit of code.

Try using these scripts, with any changes to the moving system you want.

when I receive [Level 2 Start v]
wait (pick random [4] to [10]) secs
set [moving? v] to [yes]
go to x: [0] y: [0]
show
set [number v] to (pick random [0] to [1])
if <(number) = [1]>
set [x direction v] to [1]
else
set [x direction v] to [-1]
end
set [number v] to (pick random [0] to [1])
if <(number) = [1]>
set [y direction v] to [1]
else
set [y direction v] to [-1]
end
repeat [25]
if <not <(clicked?) = [yes]>>
change x by ((x direction) * [5])
change y by ((y direction) * [5])
else
stop script
end
end
set [moving? v] to [no]
hide
when I receive [Level 2 Start v]
set size to [100] %
set [ghost v] effect to [0]
set [clicked v] to [no]
wait until <(moving?) = [yes]>
repeat until <(moving?) = [no]>
if <<touching [mouse pointer v]?> and <mouse down?>>
set [clicked v] to [yes]
set [multiplier v] to [2]
glide [1] secs to x: [0] y: [0]
repeat [50]
change [ghost v] effect by [2]
change size by [2]
end
end
This should fix your problems.  smile

Last edited by sonicfan12p (2013-01-18 11:28:30)


Why are the secret organizations getting all the attention?  mad

Offline

 

#10 2013-01-18 12:37:00

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: Please help... Having trouble with a bit of code.

Hi,

Thanks again sonicfan.  smile

I'll give it a try and report back here.

Thanks you, ErnieParke for another warm welcome.  smile
I would like to release my project this week, and i think i can make that with all this help I'm getting.  wink

Regards,

CAA14

Offline

 

#11 2013-01-18 13:46:34

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: Please help... Having trouble with a bit of code.

Question for sonicfan:

Umm, you can't set a variable to "yes".
What did you mean by that?

regards,


CAA14

Offline

 

#12 2013-01-18 14:03:03

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: Please help... Having trouble with a bit of code.

Another Question:

Wasn't there a less complicated solution?  tongue

To be honest, being totally new to scratch, I am confused by the code.
Where can i put the part about multiplying the score by 2?

Thanks again,

Regards,

CAA14

Offline

 

#13 2013-01-18 14:34:34

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: Please help... Having trouble with a bit of code.

I slightly altered the script you gave me to try to accommodate the following things:

1. I tried to make it so that The multiplier would not show up if a level had not started.
*I THINK WORKS*

2. To make it multiply "score" by 2. *WORKS*

3. To repeat a random amount of times. *DON'T KNOW IF WORKS, ALL WAYS 1*

4. To reset the size to 100% after one appearance.


The problem:

Sometimes, the multiplier shows up in the middle and does not move.


Here's the script:

[scratch]

    when I receive [lvl1_Start v]
        set size to (100)%
        set "ghost" effect to (0)
        set "clicked?" to (no)
        wait until ((multiplier_Moving?) = (yes))
        repeat until ((multiplier_Moving?) = (no)) 
            if ((touching s[mouse-pointer]?) and (mouse down?))
                set "Score" to ((Score) * (2))
                set "clicked?" to (yes)
                set "multiplier" to (2)
                glide 1 secs to x: 0 y: 0
                repeat 50 
                    change "ghost" effect by (2)
                    change size by (2)
            set "multiplier_Done" to (yes)
            wait until ((size) = (100))
            set "multiplier_Done" to (no)
    end

    when I receive [lvl1_Start v]
        set "multiplier_Done" to (no)
        set "times_To_Repeat" to (pick random (1) to (3))
        repeat (times_To_Repeat)
            wait (pick random 4 to 10) secs
            set "multiplier_Moving?" to (yes)
            go to x: 0 y: 0
            show
            set "number" to (pick random 0 to 1)
            if ((number) = (1)) else
                set "x_Direction" to (1)
            else
                set "x_Direction" to (-1)
            set "number" to (pick random 0 to 1)
            if ((number) = (1)) else
                set "y_Direction" to (1)
            else
                set "y_Direction" to (-1)
            repeat 25 
                if (not ((clicked?) = (yes))) else
                    change x by ((x_Direction) * (5))
                    change y by ((y_Direction) * (5))
                else
                    stop script
            set "multiplier_Moving?" to (no)
            hide
    end

[/scratch]

Please compare to your previous script to see what changed.
Any suggestions?


Regards,

CAA14

Offline

 

#14 2013-01-18 14:40:14

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: Please help... Having trouble with a bit of code.

Edit:

The script:



    when I receive [lvl1_Start v]
        set size to (100)%
        set "ghost" effect to (0)
        set "clicked?" to (no)
        wait until ((multiplier_Moving?) = (yes))
        repeat until ((multiplier_Moving?) = (no)) 
            if ((touching s[mouse-pointer]?) and (mouse down?))
                set "Score" to ((Score) * (2))
                set "clicked?" to (yes)
                set "multiplier" to (2)
                glide 1 secs to x: 0 y: 0
                repeat 50 
                    change "ghost" effect by (2)
                    change size by (2)
            set "multiplier_Done" to (yes)
            wait until ((size) = (100))
            set "multiplier_Done" to (no)
    end

    when I receive [lvl1_Start v]
        set "multiplier_Done" to (no)
        set "times_To_Repeat" to (pick random (1) to (3))
        repeat (times_To_Repeat)
            wait (pick random 4 to 10) secs
            set "multiplier_Moving?" to (yes)
            go to x: 0 y: 0
            show
            set "number" to (pick random 0 to 1)
            if ((number) = (1)) else
                set "x_Direction" to (1)
            else
                set "x_Direction" to (-1)
            set "number" to (pick random 0 to 1)
            if ((number) = (1)) else
                set "y_Direction" to (1)
            else
                set "y_Direction" to (-1)
            repeat 25 
                if (not ((clicked?) = (yes))) else
                    change x by ((x_Direction) * (5))
                    change y by ((y_Direction) * (5))
                else
                    stop script
            set "multiplier_Moving?" to (no)
            hide
    end

Offline

 

#15 2013-01-18 14:52:34

sonicfan12p
Scratcher
Registered: 2011-11-16
Posts: 1000+

Re: Please help... Having trouble with a bit of code.

Code:

I slightly altered the script you gave me to try to accommodate the following things:

1. I tried to make it so that The multiplier would not show up if a level had not started.
*I THINK WORKS*

2. To make it multiply "score" by 2. *WORKS*

3. To repeat a random amount of times. *DON'T KNOW IF WORKS, ALL WAYS 1*

4. To reset the size to 100% after one appearance.


The problem:

Sometimes, the multiplier shows up in the middle and does not move.


Here's the script:

[scratchblocks]

    when I receive [lvl1_Start v]
        set size to (100)%
        set [ghost v] effect to (0)
        set [clicked? v] to [no]
        wait until <(multiplier_Moving?) = [yes]>
        repeat until <(multiplier_Moving?) = [no]>  
            if <<touching [mouse-pointer v]?> and <mouse down?>> 
                set [Score v] to ((Score) * [2]) 
                set [clicked? v] to [yes]
                set [multiplier v] to [2]
                glide [1] secs to x: [0] y: [0]
                repeat [50] 
                    change [ghost v] effect by [2]
                    change size by [2]
    end
            set [multiplier_Done v] to [yes]
            wait until <(size) = [100]>
            set [multiplier_Done v] to [no]
    end
[/scratchblocks]
[scratchblocks]
    when I receive [lvl1_Start v]
        set [multiplier_Done v] to [no]
        set [times_To_Repeat v] to (pick random [1] to [3])
        repeat (times_To_Repeat)
            wait (pick random [1] to [7]) secs
            set [multiplier_Moving? v] to [yes]
            go to x: [0] y: [0]
            show
            set [number v] to (pick random [0] to [1]) // this number variable controls direction.
            if <(number) = [1]> 
                set [x_Direction v] to [1]
            else
                set [x_Direction v] to [-1]
            end
            set [number v] to (pick random [0] to [1])
            if <(number) = [1]>
                set [y_Direction v] to [1]
            else
                set [y_Direction v] to [-1]
            end
            repeat [25]  
                if <not <(clicked?) = [yes]>>
                    change x by ((x_Direction) * (5))// this changes x by 5, or -5, depending on the number variable
                    change y by ((y_Direction) * (5))//same concept as before, except with y
                else
                    stop script//this stops it from moving to random places, so it can glide to origin if clicked
             end 
             end
            set [multiplier_Moving? v] to [no]
            hide
   
[/scratchblocks]

Please compare to your previous script to see what changed.
Any suggestions?


Regards,

CAA14

How I have it set up here, it will make your sprite go in a random direction. I didn't see any problems when I looked at it first, you said it works now right? Also, I had to use the code box so you could read the comments, sorry about that.  tongue

Last edited by sonicfan12p (2013-01-18 15:29:48)


Why are the secret organizations getting all the attention?  mad

Offline

 

#16 2013-01-18 15:05:11

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: Please help... Having trouble with a bit of code.

It is with these alterations:

1. The repeat (50) block only has the two purple blocks in it; the set multiplier done to yes block, wait until size = 100 block, and the set multiplier to no block are only encapsulated in the repeat until moving = no loop and an extra repeat (times_to_repeat) block i added.

2. Also, i changed the number of seconds that it randomly picks(1 to 7 now.)

hope that's clear,

CAA14


P.S. Sorry about my block scripting skills.... sad

Offline

 

#17 2013-01-18 15:10:18

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: Please help... Having trouble with a bit of code.

I think its working now, I just tested it....

I still believe there's an easier way, like making the click thing happen if clicked and then setting a second block up that gives it several options for moving...

BTW, how does the moving thing work? it seems to move in a randomly selected line each time, i guess it has something to do with those y and x position variables....

Thanks so much for your help, brother,


CAA14

Offline

 

#18 2013-01-18 15:22:24

sonicfan12p
Scratcher
Registered: 2011-11-16
Posts: 1000+

Re: Please help... Having trouble with a bit of code.

CAA14 wrote:

I think its working now, I just tested it....

I still believe there's an easier way, like making the click thing happen if clicked and then setting a second block up that gives it several options for moving...

BTW, how does the moving thing work? it seems to move in a randomly selected line each time, i guess it has something to do with those y and x position variables....

Thanks so much for your help, brother,


CAA14

Alright, I'll edit it with some comment to help, and change what you said was changed.
Edit: Done.

Last edited by sonicfan12p (2013-01-18 15:30:17)


Why are the secret organizations getting all the attention?  mad

Offline

 

#19 2013-01-18 15:47:00

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: Please help... Having trouble with a bit of code.

Hi,

Thanks alot sonicfan,

regards,

CAA14

P.S. Just wondering, what is the variable, "multiplier" doing?

My score is going crazy, it will add the correct amount of points if the cross-hair hits a certain color on the target the first time, but then add insane amounts of points to "score" after that.

To bad I'm a new scratcher... otherwise i'd send you a picture of my score scripts aswell...

Offline

 

#20 2013-01-18 15:52:13

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: Please help... Having trouble with a bit of code.

Ok, i just saw your code box you sent earlier(for some reason it did not show up before, weird). I sort of understand, and I want to thank you again for your time and patients with this newbie.  smile 

I think the multiplier is working well, but the score of my project(as posted above) is going crazy.... i cant find a bug.  sad


I think it will just take me time and experience to understand how that script got those random directions...

CAA14

Offline

 

#21 2013-01-18 15:54:33

sonicfan12p
Scratcher
Registered: 2011-11-16
Posts: 1000+

Re: Please help... Having trouble with a bit of code.

Well, I meant it to be what multiplies your score, as in the other targets giving you whatever score they give you, times the multiplier. Just a thought, but if you already had that part worked out it's uneccessary. You could upload your project as a beta and I could look at it if it gets too out of control.


Why are the secret organizations getting all the attention?  mad

Offline

 

#22 2013-01-18 15:56:47

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: Please help... Having trouble with a bit of code.

Hi,

What's a "beta"

If its what i think it is, it's an unfinished program.

Regards,

CAA14

Offline

 

#23 2013-01-18 15:59:25

sonicfan12p
Scratcher
Registered: 2011-11-16
Posts: 1000+

Re: Please help... Having trouble with a bit of code.

CAA14 wrote:

Hi,

What's a "beta"

If its what i think it is, it's an unfinished program.

Regards,

CAA14

Yes, it's one of two test stages, alpha, and beta. Scratch 2.0 is currently in alpha stage, on the 28th it will go to beta stage, if that helps. To upload something as a beta, just upload it with beta in the name. Normally only people who are asked to look at them look at them, so if you want to keep it hidden until release, this won't affect that.


Why are the secret organizations getting all the attention?  mad

Offline

 

#24 2013-01-18 16:12:16

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: Please help... Having trouble with a bit of code.

Ok, Cool.

My project is in beta stage I guess.  wink

I will probably do that later... I want to look at it some more before I upload it... Just in case I can save you that work!  big_smile


Regards,

CAA14

Offline

 

#25 2013-01-18 19:10:08

Blazingwave
Scratcher
Registered: 2012-10-27
Posts: 500+

Re: Please help... Having trouble with a bit of code.

CAA14 wrote:

Question for sonicfan:

Umm, you can't set a variable to "yes".
What did you mean by that?

regards,


CAA14

You indeed can set a variable to "yes" though it doesn't have any meaning until you add something like "if variable = yes do this"


http://i42.tinypic.com/t8nrlh.gif  http://blocks.scratchr.org/API.php?user=Blazingwave&amp;action=onlineStatus&amp;online=http://i49.tinypic.com/25flloj.gif=http://i45.tinypic.com/o8i97l.gif
http://i41.tinypic.com/s1lyyo.jpg

Offline

 

Board footer