Discuss Scratch

SpriteProductionS
Scratcher
100+ posts

┌ How To Use Less Scripts ┘?

How can I use less scripts in my projects? im starting to notice that when i make a project it tends to have a bunch of scripts(while being very short)
then I see more complex projects that have 30% less scripts, why does this occur?

M Y B E S T S C R A T C H P R O J E C T B Y F A R ?⬇️️ -SpriteProductionS- “For your entertainment…” (click below)




TheDigitalDev
Scratcher
100+ posts

┌ How To Use Less Scripts ┘?

Everyone has a different style of programming. Usually people who have less scripts merge scripts in sacrifice of organization. Like multiple green flag scripts in different objects, so they'll merge those. Or maybe it's just they do things more efficiently.

Last edited by TheDigitalDev (Feb. 22, 2017 09:08:56)


Call me Digi

My System: i5-6600k @ 3.5Ghz // Nvidia GTX 1070 // 8gb RAM // Windows 10 & Arch Linux
|| My GitHub || Sneak peak of my project
deck26
Scratcher
1000+ posts

┌ How To Use Less Scripts ┘?

The number of scripts is not necessarily the issue. I'd rather look at a project with 10 well organised scripts than one where everything has been crammed into one script which is hard to follow. So getting organised is the key.

For example, variables often need to be intialised so have a single initialisation script for each sprite that need to initialise anything. Only once these have completed should game play start so use a control script to ‘broadcast initialise and wait’ and then ‘broadcast game-start’.

Watch for chances to combine scripts. If a sprite has two or more forever loops checking for key presses or variable changes or whatever but each ‘if’ block is fairly simple and includes no ‘wait’s of any kind then these can probably be combined into a single forever loop.

If you're using cloning it is often useful to hide the sprite and only work with clones so you don't need to repeat code.

If you ever find yourself repeating code with minor differences try to generalise the code and use a variable to handle the bits that change. Don't have a script that starts when level 1 is started, waits until score is over 10 and broadcasts level 2 and then do the same with level 2/3/4/5/6 with different score values - use a list and check whether you've reached the relevant value for the current level.

That's the sort of thing you need to do to get fewer scripts.

(Minor point - ‘fewer’ if something is countable, ‘less’ if not. So ‘fewer apples/scripts/people’ but ‘less water/grass/attention’.)
SpriteProductionS
Scratcher
100+ posts

┌ How To Use Less Scripts ┘?

Thanks, I noticed Clone Id's Is a common use but how does that work ? @deck26

Last edited by SpriteProductionS (Feb. 22, 2017 09:32:09)


M Y B E S T S C R A T C H P R O J E C T B Y F A R ?⬇️️ -SpriteProductionS- “For your entertainment…” (click below)




deck26
Scratcher
1000+ posts

┌ How To Use Less Scripts ┘?

https://scratch.mit.edu/projects/111228685/ may help. Variables that are local (this sprite only) are inherited by clones so they have their own copy with the initial value that the creating object had. So if cloneID is a local variable each clone can be given its own value as follows.

set [cloneID v] to [1]
repeat (5)
create clone of [myself v]
change [cloneID v] by [1]
end
would create 5 clones with cloneID values 1 to 5.

Of course, the variable doesn't have to be called cloneID.

Powered by DjangoBB