# Can anyone help me shorten my code? or less heavy? (plus how to make a restart button)

**URL:** <https://discourse.processing.org/t/can-anyone-help-me-shorten-my-code-or-less-heavy-plus-how-to-make-a-restart-button/19729>\
**Category:** Coding Questions\
**Created:** [April 13, 2020, 7:26am UTC](https://discourse.processing.org/t/can-anyone-help-me-shorten-my-code-or-less-heavy-plus-how-to-make-a-restart-button/19729 "2020-04-13T07:26:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![haree2000](https://avatars.discourse-cdn.com/v4/letter/h/85e7bf/32.png) [@haree2000](https://discourse.processing.org/u/haree2000)\
**Post date:** [April 13, 2020, 7:26am UTC](https://discourse.processing.org/t/can-anyone-help-me-shorten-my-code-or-less-heavy-plus-how-to-make-a-restart-button/19729/1 "2020-04-13T07:26:58Z")

</div>

hey! I’m still really new to processing TT  
but I’m getting there!!

right now I want to make a short interactive story using processing(IDK if that’s a good idea or not but I’m trying!)

so I got it down pretty well!! but it’s just A LOT OF CODE  
like ti takes 35 seconds to load every time I run it

and I basically just muscled through and made the code super long but I’m pretty sure there must be a way to shorten it!

p.s I would also appreciate it if someone could help me make a restart button… TT  
I am new with it comes to SCENE transfers so I’m not really sure how to make a restart button besides making a specific button for each ending that’ll take it back to the beginning but I’m wondering if there’s just a way to make a button class that will automatically go to the beginning and I can just simply put it at the end of any scene I want.

MY CODE:

---

<div class="post-metadata">

**Author:** ![haree2000](https://avatars.discourse-cdn.com/v4/letter/h/85e7bf/32.png) [@haree2000](https://discourse.processing.org/u/haree2000)\
**Post date:** [April 13, 2020, 7:29am UTC](https://discourse.processing.org/t/can-anyone-help-me-shorten-my-code-or-less-heavy-plus-how-to-make-a-restart-button/19729/2 "2020-04-13T07:29:24Z")

</div>

I dunno why it won’t let me post a PASTEBIN link so I have a google docs instead.

> **[PASTEBIN](https://docs.google.com/document/d/12sLHq1edUPewUYcYjrx15sAgB5R662HxUstaV0u_2FE/edit?usp=sharing)**
>
> PASTEBIN https://pastebin.com/i5Q9c7yp MY CODE: /\*\*\*\*\*\*\*\*\* VARIABLES \*\*\*\*\*\*\*\*\*/ //importing video import processing.video.\*; Movie StarbucksStory; //importing sound import processing.sound.\*; SoundFile BGMusic; //for the messages int...

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [April 13, 2020, 11:12am UTC](https://discourse.processing.org/t/can-anyone-help-me-shorten-my-code-or-less-heavy-plus-how-to-make-a-restart-button/19729/3 "2020-04-13T11:12:56Z")

</div>

> [@haree2000](#):
>
> like ti takes 35 seconds to load every time I run it

I suspect that this is just because it is loading a lot of resources especially the sound and movies files so not much you can do there.

> [@haree2000](#):
>
> I’m not really sure how to make a restart button besides making a specific button for each ending that’ll take it back to the beginning but I’m wondering if there’s just a way to make a button class t

If you simply want a visible button that you can click then there are GUI libraries available e.g. G4P and controlP5 both of which are very popular.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 15, 2020, 2:55pm UTC](https://discourse.processing.org/t/can-anyone-help-me-shorten-my-code-or-less-heavy-plus-how-to-make-a-restart-button/19729/4 "2020-04-15T14:55:53Z")

</div>

1. [WET vs DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself): I see blocks of similar code like “text box outline” dozens of times. Try making those functions. That will eg turn 6 lines into 1 many places.

2. Load just in time. Is this a visual novel with a limited number of next scenes? If so, consider only loading things like images in the scene just before you need them (or when a scene starts). Then you don’t have to preload everything all at once.
