[Request] Jump to label - Performance improvement

Post your work in progress addons and get feedback

Post » Sun Nov 16, 2014 1:10 pm

Hello everyone,

I would like to suggest an addon which I have seen in RPG maker software so far. I think it might not be that easy to program it, but I think it`s worth it because this addon helps you to significantly improve the performance of your project.

The addon should allow you to place labels inside the code of your event sheets and to call actions in other places which will make C2 jump to that label, which means that C2 skips the code between the 'Jump to label' and the 'Label' command and executes the code from the 'Label' position.

How is that handy? I'll give you two examples (which are attached to this post):

In example 1, C2 checks every 5 seconds which value the variable 'Sound_Variable' occupies and plays a sound corresponding of the variable's value. As the value reaches from 1 to 100, C2 will have to check 100 conditions, which certainly decreases the FPS, before it can create the object 'Blue'. Let's say that Sound_Variable has a value of 48, then C2 will still have to check condition 49 to 100 and determine them as false. By using the 'Jump to label' addon, this becomes avoidable:

In example 2 you can see that there is a label called 'Label1' at the end of the 100 conditions and each condition contains a Jump to label action. Lets say that Sound_Variable=48 and so condition 48 is true, C2 will read the Jump to label1 action and skip all conditions from 49 to 100 and execute the code from the Label1 position on, then create the object 'Blue', which increases the FPS in comparison to example 1.

Is it possible to create an addon like this?
You do not have the required permissions to view the files attached to this post.
B
13
S
3
G
1
Posts: 93
Reputation: 1,481

Post » Tue Nov 18, 2014 5:07 pm

First off, you could simplify all 100 sound checks into 1 event.

Also check out the action "Wait for Signal" to see if that will do what you are trying to replicate.
B
87
S
44
G
16
Posts: 1,005
Reputation: 17,938

Post » Tue Nov 18, 2014 5:12 pm

System (Every 5 seconds) -> Play "Sound_Variable"

*Make sure your variable is set to "text" and the value is just the name of the sound file, without the extension
B
87
S
44
G
16
Posts: 1,005
Reputation: 17,938

Post » Wed Nov 19, 2014 6:24 pm

Thanks for the answer!

The event sheets I posted above were meant as examples to point out what kind of addon I'm asking for, I'm not actually using these event sheets in any of my games. Instead of checking for Sound_Variables and playing sounds, there could be any kind of action instead.

I'm just disappointed by the fact that C2 has no option to abort the processing at certain positions in the event sheets, or to simply skip code to improve performance.
B
13
S
3
G
1
Posts: 93
Reputation: 1,481

Post » Wed Nov 19, 2014 6:37 pm

"I'm just disappointed by the fact that C2 has no option to abort the processing at certain positions in the event sheets, or to simply skip code to improve performance."

It can, theres a ton of different ways.
Nothing wrong with using Boolean variables either.
Not to mention a ton of different ways to not have to repeat code, like play by name, etc.
Image ImageImage
B
169
S
50
G
174
Posts: 8,323
Reputation: 110,790

Post » Sat Nov 22, 2014 3:53 am

this is basically a goto, which is something you really avoid in all programming languages because it makes code horrendously spaghetti like and hard to manage. You need to give a good use case to justify something like this, and you're example wasn't one, no example for goto's ever are. you could use the stop loop condition, or simply use a variable to choose the right sound. there are ways around goto's and goto's should be avoided.
B
77
S
13
G
8
Posts: 1,974
Reputation: 9,893

Post » Sat Nov 22, 2014 4:08 pm

Also against that, this would not be worth the effort, as the performance gain would be minimalist when you design your game with a good organisation (and also, that would actually break the organisation, which is a 100% no go in C2, where organising is really mandatory).As goto feels more like a cheap way to skip entire part of the code that will bite your hand when you will have to redesign some parts.

To be fair, if you have performances issues due to that kind of problem (like the one you exposed, aka potential useless or redondant checks), rethink the design, in your case, you could either do:

Play sound "Sound"&Sound_Variable (one action, no conditions, opposed to your 100 comparisons with the associated action play sound)

Or have a list List="sound1,sound2,sound3" etc..

Play sound tokenat(List, ",", Sound_Variable-1)
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Sat Nov 22, 2014 6:10 pm

As already mentioned your original example doesn't need this feature. Also you can make events that skip un-necessary work - just put them in a sub-event to an event that checks if the work really needs to be done.

Probably the best substitute for this feature is the existing Function object. That can be thought of as a go-to-event followed by a return-to-caller, supports parameters and recursion, and can go a long way to making your events more readable.
Scirra Founder
B
398
S
236
G
88
Posts: 24,428
Reputation: 194,600

Post » Sun Nov 23, 2014 1:45 pm

I guess I`ll have to find a way to work around the issues of my project then.

It is possible to play a sound by name, which is an elegant way to shorten the code, but there is no such thing as 'create object by name', which forces me to use a lot of condition checks. Any idea on how to simplify this? Even when making use of functions, I'd still have to check for each value of the used variable and create objects according to these.

(By the way, English isn't my native language, that's why my grammar might be awkward sometimes :P )
B
13
S
3
G
1
Posts: 93
Reputation: 1,481

Post » Mon Nov 24, 2014 3:07 am

@Ashley

I would like to have "wait signal" SDK, to allow 3rd-party add/embed customize "wait signal" into actions.
B
108
S
26
G
272
Posts: 4,471
Reputation: 152,277


Return to Work in Progress Addons

Who is online

Users browsing this forum: No registered users and 2 guests