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

#1 2011-10-31 13:05:19

dobbyjones
New Scratcher
Registered: 2011-10-31
Posts: 2

Scratch Function?

hi,
I am very new to Sense (Scratch) and have a little experience with VB programming, I was wondering if there is a way of adding Fubctions to Scratch / Sense i.e. if I had loads of code some of which was the same and I didn't want to rewrite or copy it everytime I wanted to use it, I could use a Function to put it in and then Call the Function when I needed it - thos would reduce the amount of scripting code in the program.
Any suggestions please, and please be gentle - I am only a beginner after all.

Thanx  smile

Offline

 

#2 2011-10-31 13:17:14

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: Scratch Function?

Sorry I don't really get what you mean completely.
You could instead of putting lots of times in differents 'ifs', but an 'or' (found in operators) and put all the things you want it to react to in their.


Why

Offline

 

#3 2011-10-31 13:26:52

dobbyjones
New Scratcher
Registered: 2011-10-31
Posts: 2

Re: Scratch Function?

Hi RedRocker227,

Thank you for your reply....I mean if I had a simple program to show a numeric power i.e 2 x 4 = 16 2 to the power 4 = 16 and then I wanted to re-run the program, I would use variables for the number and the power of, so if I wanted to reset the variables each time I used them to zero I would have to rewrite:
Set Variable1 to 0
Set Variable2 to 0

and so on

can I put that code in a Function like you would in visual basic?

Offline

 

#4 2011-10-31 13:59:08

GurkinC
Scratcher
Registered: 2009-11-30
Posts: 100+

Re: Scratch Function?

The simplest way is just to right click and click duplicate script. There is no way to create a function as such.


Try my latest game, Rolling 2, a 10-level platform game based around the gravity marble.

Offline

 

#5 2011-10-31 14:57:42

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: Scratch Function?

Yes, creating functions is unfortunately not supported in the current version of Scratch. It's a major feature in the next release, (version 2.0) however.  smile

http://blog.scratch.mit.edu/2011/03/scr … -your.html


http://www.blocks.scratchr.org/API.php?action=random&return=image&link1=http://i.imgur.com/OZn2RD3.png&link2=http://i.imgur.com/duzaGTB.png&link3=http://i.imgur.com/CrDGvvZ.png&link4=http://i.imgur.com/POEpQyZ.png&link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#6 2011-11-02 20:29:59

Greatdane
Scratcher
Registered: 2007-06-05
Posts: 1000+

Re: Scratch Function?

EDIT: My short attention led me to not read anything else, derp. >.<
http://i.imgur.com/I0KJL.gif


I've been experimenting with creating a project API using broadcasts and lists in order to run a function and its parameters.

However, you can do something like this:
In Sprite 1
http://i41.tinypic.com/rh0qcy.gif
The sprite broadcasts something and a couple of global parameters are set. You can also use lists.
In Sprite 2
http://i.imgur.com/bwiIF.gif
This sprite recieves the broadcast and the parameters set earlier.

Last edited by Greatdane (2011-11-02 20:38:35)


The future belongs to those who believe in the beauty of their dreams.
        ~ Eleanor Roosevelt

Offline

 

Board footer