[SOLVED] No If statements?

0 favourites
  • Ok, i am new to Construct, but i am finding it a little crippled.

    The event sheet is run every tick right? So that means it is very difficult to set game level actions.

    I want to spawn my animals (not enemies) when the game loads. There will be between 1 and 10 of them. I want to spawn them at 1 second intervals. The only way i can get them to spawn is with "on end of layout" or "on start of layout." - I have no idea why that is.

    I have a spawn function, this is fine. I call it with Repeat using a variable i set.

    I would like them to appear one by one with a delay of 1 second. This is not possible with the wait function as the function can only be called at the start of the game. I cannot use an IF statement to see how many have been spawned and use that as a limit.

    Please can someone tell me how you control spawning within fixed amounts instead of generating them all at once on load.

    The event sheet is called 1 time per tick but also there are no IF statements so standard approaches to coding seem to be useless here.

  • All conditions are if statements.

  • Ok, i am new to Construct, but i am finding it a little crippled.

    The event sheet is run every tick right? So that means it is very difficult to set game level actions.

    I want to spawn my animals (not enemies) when the game loads. There will be between 1 and 10 of them. I want to spawn them at 1 second intervals. The only way i can get them to spawn is with "on end of layout" or "on start of layout." - I have no idea why that is.

    I have a spawn function, this is fine. I call it with Repeat using a variable i set.

    I would like them to appear one by one with a delay of 1 second. This is not possible with the wait function as the function can only be called at the start of the game. I cannot use an IF statement to see how many have been spawned and use that as a limit.

    Please can someone tell me how you control spawning within fixed amounts instead of generating them all at once on load.

    The event sheet is called 1 time per tick but also there are no IF statements so standard approaches to coding seem to be useless here.

    Please read the manual and try the built-in templates, and maybe a few tutorials before making wildly misinformed statements.

    All the information on the Event system is fully documented in the manual.

  • zenox98 - I have gone through the manual and several templates, hence the question.

    It's a little dissappointing that rather than point me to a specific template or area of the manual you just blast me for being wildly misinformed.

    The event system information is what leads me to state that the event sheet is executed each tick.

    Please, if I am so wildy mis-informed direct me to somewhere i can read more.

  • Start with what are the conditions you want.

    Between 1 and 10 every second when the game loads doesn't make much sense.

  • No.

    When the game starts a couple of global variables are set.

    The quantity of animals to spawn - between 1 and 10. (howMany)

    A variable that selects which animal is used based on an array. (whichAnimal)

    This quantity of animals need to be spawned consequetively, not all at once. Ideally, once every 0.5 seconds until they are all there.

    I have a spawn function that creates the right animal in a random location, right now it is repeated for the quantity.

    It is triggered on "on loader complete" because i cannot find another trigger to get it to run.

    The idea is that a random number of animal sprites are created at the start of the game. They can be of a number of different types. Right now they all appear suddenly, I would like to have them appear individually one after another. This is a counting game for children.

    How can i set up the calls to the spawn function to take place in sequence.

    For example

    for(howMany){

    spawnAnimal();

    wait(0.5 seconds)

    }

    If i do anythying like this there is no limit to the spawning. The loop does not end.

    Only by calling "On loader layout complete" -> Function Call spawnAnimal()" do i get the limit on the amount spawned. It calls it once. Then i use Repeat (howMany) to repeat the call for the number of animals i want.

    Also if i add any kind of wait to the function or the call, it is simply ignored.

    How can i add a condition somewhere to do this with a time delay until a condition is met or for each instance until there are "howMany" on screen.

  • This is something pretty straightforward to do with timers.

    Here's a small example.

  • Magistross - I get a message about release 247 vs my release 244.

    I installed construct 2 yesterday, are you on a different release?

  • It's a beta version released in september. Makes me realise we are long overdue a stable release !

    You could install r249 and it should open sucessfully.

  • The basics:

    On start of layout, set variable "howmany" to int(random(10)), set variable "canspawn" to 1

    variable "canspawn" = 1

    ->variable animalcount< variable "howmany"

    -->every 1 seconds, system create object animal at random x y, add 1 to variable animalcount

    I would suggest looking up how variable comparisons work, globals, instance.

    Note loader complete is for loader layouts, stick to on start of layout.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • two ways to do what you want is with this:

    +----------------------------------------+
    |system: compare animals.count < howMany | system: create animal at (0,0)
    |system: every 1 seconds                 |
    +----------------------------------------+[/code:2bs9nz4c]
    or this:
    [code:2bs9nz4c]+-----------------------------+
    |system: start of layout      | wait 0.5*loopindex seconds
    |system: repeat howMany times | system: create animal at (0,0)
    +-----------------------------+[/code:2bs9nz4c]
    
    You cannot use wait like you do in that for loop in your post because it doesn't pause the loop, rather it delays the actions and sub events after it.
  • newt

    Thank you very much, i was able to implement that without any great problems but I dont think we need the canspawn variable. Once the animalCount is no longer < howMany, the spawning stops.

    I appreciate all the help here.

    I did look at the tutorials and manual, but I could not find anything that explained this.

    Thanks

    Oh and Magistross - I can't install anything but the stable version, i am using Construct by order of a client - hence the lack of experience. If i get enough work from them then i will be buying the liscence but right now this first task is paying only the same as the cost of the license itself.

  • jezjones24

    To open a capx created with newer version of C2, rename it to zip, unpack to a folder, open .caproj file in Notepad and edit this line:

    <saved-with-version>24600</saved-with-version>

    (I post this advice so often, I should add it to my signature )

  • Still having trouble with conditions.

    I am trying to compare the instance variable of a button being clicked with the variable for the number of animals on screen.

    I have buttons 1 to 10 and i would like to show Win/Lose depending which was pressed.

    I am using button->compare instance variable, but it seems to be executed every tick, not on the click of the button.

    I tried to put it in the button->onclick event but there is no option at that stage to compare the variables.

    I also tried making a function and giving it an event condition for if the passed parameter of the instance variable was correct it would execute. That worked, but it gives me no way to deal with a wrong value being passed.

    Again, i am looking for IF & Else here but the logic escapes me.

    Any suggestions?

  • You add the compare as a condition, press C, you can add the compare vars after the initial on button clicked, so it becomes on button clicked, if var=var, do this. In C2, the ifs are just conditions. It will only execute actions on the right if the conditions on the left are true. So if you click the button and those vars do not meet the condition you want, then clicking the button will not execute the action on the right and do nothing at all.

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