How do I improve this function? Cap attached

0 favourites
  • 15 posts
From the Asset Store
City ride is a game to improve your memory.You have to focus and remember the information related to passengers of previ
  • Hello, Finally I am making good use of functions. I used to fear them but now I love them. However, I know there is more to them than I know.

    Basically, rather than repeat this code on every new level, is there a way to use a function with a param instead? Not sure how to go about this. (Or if it can be done)

    Thanks for the help!

    Tagged:

  • Yes, you can pass any number of parameters to functions, and access these parameters inside the function using Function.Param(0), Function.Param(1) etc..

    So in your case you can call function "AddAmmo" with parameter 6, and inside the function use "Add Function.Param(0) to ammo"

  • Cheers Dop, I will give that a go and see how it works :-)

  • Yes, you can pass any number of parameters to functions, and access these parameters inside the function using Function.Param(0), Function.Param(1) etc..

    So in your case you can call function "AddAmmo" with parameter 6, and inside the function use "Add Function.Param(0) to ammo"

    Hi dop, sorry for being a layman, Is this the right way to set up the function. I have tried a lot of different ways but nothings working.

  • .

  • Thanks Dop, It does set the ammo but when I fire the arrow the ammo drops to minus 3.

    Not sure why, But I will just stick with setting it at the start. Cheers buddy

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Why do you have param(8)?? It should be param(0) for the first parameter, param(1) for second parameter etc. 0 is the index of the parameter, not the number of bullets.

    Also, I have no idea what's happening when you fire a bullet, this isn't in your screenshot. In theory you should check if ammo>0 and subtract 1 from ammo.

  • Why do you have param(8)?? It should be param(0) for the first parameter, param(1) for second parameter etc. 0 is the index of the parameter, not the number of bullets.

    Also, I have no idea what's happening when you fire a bullet, this isn't in your screenshot. In theory you should check if ammo>0 and subtract 1 from ammo.

    Lol, god Dop, I have no idea? I am totally spun out about this. I honestly dont whats going on anymore. Its so messed up. Basically when you push the shoot button it spawns an arrow. But I just want it so at the start of the layout it adds to the arrow text (capture 2)

    Cheers Dop :-)

  • Now you are adding 0 (zero) to the ammo, why?!

    see this example, you can open it in Conctruct 3:

    dropbox.com/s/9tml5fo5gqzoblv/ammo_test.capx

  • Now you are adding 0 (zero) to the ammo, why?!

    see this example, you can open it in Conctruct 3:

    https://www.dropbox.com/s/9tml5fo5gqzoblv/ammo_test.capx?dl=0

    Thanks for that example dop man. I have studied it and it makes perfect sense. I see how it works.

    Somethings not right in the game, Its not working when i put it in. I will work it out. I think its colliding with some other stuff that going on. Thanks for your patience and thanks for a great example, that was quality"! :-)

  • My whole code is messed up. Its a total nightmare. It will work, but I have to go through everything and make adjustments.

    Building a game is hard man.

    Thanks dop

  • functions if you look at them have parameters which you can define

    the order of those parameters are 0 = being first 1 = being second and so on, you can add a N numbers of parameters

    in order to set a value at a surtain parameter you do the plus sign on the call function .. or set function .. and a parameter is added then u add a value in it being it text or number.

    then to use the parameter u call its position from top to bottom, if its the 1st on top then u use 0 as explained above if its the 5th parameter in order u call it by using 4 and so on.

    the order of the parameters follows the same numerical order as loopindex... they count starting and including 0 not from 1.

    take for example a function named "set_stats" with 5 different parameters

    and we do the parameters like this

    0 = 100

    1 = 10

    2 = 5

    3 = 200

    4 = 50

    lets say the stats are to be set for a character with the following variables defaultHealth, Strength,

    Stamina, Defense, Coins.

    then when we call "set_stats"

    C :< Call Function "set_stats"

    --------------------------------A :< set player variable defaultHealth to function parameter 0

    --------------------------------A :< set player variable Strength to function parameter 1

    --------------------------------A :< set player variable Stamina to function parameter 2

    --------------------------------A :< set player variable Defense to function parameter 3

    --------------------------------A :< set player variable Coins to function parameter 4

    Building a game is a pain ^_^ ...

  • Hey bud, thanks George. I am going to play around with this because I never even thought of calling an instance variable with a function. I can see how that would make things easier.

    I guess I struggle with where to put the function as well.

    Because the function can go in a condition, sub condition and even an action!

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