How do I clean up this code?

0 favourites
  • 9 posts
From the Asset Store
Two levels with two sistem Wave. with Source-code (.c3p) + HTML5 Exported.
  • <img src="{SMILIES_PATH}/icon_idea.gif" alt=":idea:" title="Idea"> I came up with a way that lets me have fading layers and sprites of the same type setup across the different layers and have my mouse properly tell me which one is active, limited by which one is currently visible.

    CAPX : http://d.pr/f/uTA7/2HMUdXCi

    My question is... am I doing this in a bad way? Is there a better way I can do it? Is there a cleaner way I can do it? This is just a test version to show you how im doing it, but if I am going to go ahead with this in my actual code, it's going to be a LOT of garbagey stuff I feel like there must be a way more efficient way to get the same results?

    Would madly appreciate any help, if you have any time to check.

    Thank you!

    Nate

  • Use functions. With return value. That way you only code once and can call/use that function(code) all over the place.

  • Use functions. With return value. That way you only code once and can call/use that function(code) all over the place.

    I thought the problem with functions in this case is they don't continually run. so where i want the layers to fade into one another, a function cant do that (am i wrong) because it just 'starts' to set the opacity of the layer, then stops after the first tick.

    Hoping for some genius wisdom to cause a paradigm shift in my thinking tho. Ive tried functions and just couldnt get it working as i need here.

  • Functions are used for repetitive code. You've got three sets of events doing exactly the same thing except the name of the layer being checked. Convert one of those blocks to be inside a function, using Function.Param(0) as the name to be checked, and replace the current blocks with a function call.

    (You can't use Trigger once in this case, but that's a small loss, and not critical in this case.)

  • You did it. you blew my mind. i never once thought i could/should call a function every tick like that. seems dumb now that i realize it... its doing what i was already doing every tick...

    thanks man.

  • I'm sure you've used Functіons in your code before? Anyway the repetitive checking of 'activeLayer' had me twitching, checking the same thing 4 times in a row, so here's a slight mod of blackhornet's mod. Also, why set the red/blue/green in events instead of in properties? I guess because it's just a sample capx, but anyway I changed that too. I'm not a fan of using UID directly like that.

    [attachment=0:3teoydhf][/attachment:3teoydhf]

  • Yeah i use functions all over the place, but it was always for triggered stuff like.... hard to explain... like 'doing stuff on an action' type stuff. i didnt really think to use them in situations where they're checked every tick.. for some reason i thought that would be inefficient haha. im a lil embarrassed by it, of course.

  • I thought the problem with functions in this case is they don't continually run. so where i want the layers to fade into one another, a function cant do that (am i wrong) because it just 'starts' to set the opacity of the layer, then stops after the first tick.

    Hoping for some genius wisdom to cause a paradigm shift in my thinking tho. Ive tried functions and just couldnt get it working as i need here.

    Wow, see you got some great stuff from the others

    Yes, functions can continually run. As long as you give it a reason to run.

    Call it everytick works or you can give it a reason to run

    Just as example

    run function = 1

    if run fuction = 1

    and x<100

    do this or that

    else

    run function = 0 x =99

    or whatever floats your boat.

    Remember every tick is reading your eventsheets from top to bottom and if a condition isn't met the function/code will run until that condition is met.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • time to clean up haha

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)