How do I improve this code? it works perfect, but there is alot of actions.

0 favourites
  • 13 posts
From the Asset Store
5 levels with simple coding Source-code (.c3p) + HTML5 Exported
  • Hello,

    Basically when the player fires the arrow, a text bubble pops up. Then it gets destroyed after two seconds. Then a friends text box pops up.

    There will be about 8 text boxes in total.

    I have tried to use a function to chop down the code, but it docent really work because each text box is different. I have tried cloning one text box and picking each by unique id with a function with no success.

    Should i just carry on with the actions and separate it with blank sub events? is this ok practice?

    Thanks for any help.

    Tagged:

  • It doesn't seem to be doing what you described but yes a function is best to cut down repeating code. You said something happens when the player fires an arrow but the logic shown suggests you are checking a variable on start of layout. Also I can't see what you've put in the function.

  • It doesn't seem to be doing what you described but yes a function is best to cut down repeating code. You said something happens when the player fires an arrow but the logic shown suggests you are checking a variable on start of layout. Also I can't see what you've put in the function.

    I have started a new test project around this. I feel i am getting close. But somethings not right. The friends text spawns at the same time as the players. even though i have selected the friends uid text.

  • You are running the same function twice, is that correct? If those are the events in the function then you don't need to use a function, they are actions that can just go in place of the function call.

  • Thanks, so if i have about 50 actions is that too many?

  • Where are the 50 actions? Can you explain how you are planning to expand it. At the moment a text box alternates between being shown for a player and a friend right?

  • the circled events spawns a textbox then destroys it after two seconds. I will need to repeat this for each separate text, which will cause quite a few actions. 36 in total.

    I just expand it by continuing to add the same action with different text boxes.

    Yeah at the moment a pop up goes above the player, then disappears, then a second later a text box appears above the friend and disappears. Runs well.

    I have read a few posts about dialogue and there seems to be alot of complication around it. This works and is simple, but its just long. + im inexperienced so it could be all wrong!

  • Yeah you don't destroy and create new text objects for text. You keep the one object there, change its visibility and change its text from a variable or something. Destroying a text object and replacing it with a different text object is redundant in this scenario. If the purpose is to set different text then you focus on the set text action with the same text object.

  • Yeah you don't destroy and create new text objects for text. You keep the one object there, change its visibility and change its text from a variable or something. Destroying a text object and replacing it with a different text object is redundant in this scenario. If the purpose is to set different text then you focus on the set text action with the same text object.

    Perfect Plinkie,

    Thank you for that advice. I only used one text event! I even managed to squeeze a function in there for the colour of the text ect. Looks alot cleaner and works!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)