How do I make random events?

From the Asset Store
14 amazing sound files of game events like Level Ups, Level Completes, object spawn, object taking etc.
  • Hello, I've at least 100 random events in my game. They appear every 10 seconds. They are like:

    1)There is a pandemic. Will you open hospitals?

    -Yes -No

    2)They kidnapped you. Will you try to run?

    -Yes -No

    3)There was an earthquake. Will you run for help to people?

    -Yes -No

    Every yes and no answer has its own consequences. For example: If my player says Yes, his popularity will increase by 50, his money will increase by 1000 and his success will increase by 20. Money, popularity and success are my three global variables. So, when my player chooses yes or no my global variables will change accordingly. Yet, I don't know how to do that. Here's my array:

    If you share an example I would appreciate it.

  • Are the choices always going to be yes and no?

  • Are the choices always going to be yes and no?

    if yes..

    Just save your array like:

    0,0 There is a pandemic. Will you open hospitals?

    0,1 Amount of money, for yes

    0,2 Amount of popularity, for yes

    0,3 Amount of success, for yes

    0,4 Amount of money, for no

    0,5 Amount of popularity, for no

    0,6 Amount of success, for no

    1.0 Next question..

  • Dear klabundee and oosyrag,

    Yes, the answer always going to be yes and no. When I save my array as you said, what should I do next?

    Thank u both for answering.

  • Dear klabundee and oosyrag,

    Yes, the answer always going to be yes and no. When I save my array as you said, what should I do next?

    Thank u both for answering.

    The way I said is just one way.. its a simple one..

    First, store the index of the array, for example..

    Your current question is 5.0, so you know that the values to consider are on 5.1 5.2 and 5.3 to yes, and 5.4, 5.5 and 5.6 to no.

    On button click yes:

    Set value "Money" to (Self)+(1,index.array)

    Set value "Popularity" to (Self)+(2,index.array)

    Set value "Success" to (Self)+(3,index.array)

    On button click no:

    Set value "Money" to (Self)+(4,index.array)

    Set value "Popularity" to (Self)+(5,index.array)

    Set value "Success" to (Self)+(6,index.array)

    You may also need to compare before set the value to the variable if its negative or positive..

    Here, just made an example:

    mega.nz/file/M1hwwDxR

  • klabundee and mrcgkh,

    You guys are literally amazing. Thank you.

  • Hi, klabundee and mrcgkh

    I'll ask one thing; My events should come once, I mean sometimes the same event comes three-four times in a row and I want my events to come only once in the game. How can I do that? Should I use ''advance random'' or is there any other way?

    Thank u.

  • Advanced random is good, it can pick a random number from a set without repeating.

    Alternatively, after you pick a row from the array, just delete it out of the array.

  • You can create an randomized array but it will not guarantee a repetition. For example you have 4(numbered as 0,1,2,3) events. You put them in an array and shuffled it. And on every 4 events you will shuffle again

    Group 1 Group 2 Group 3

    (0,3,1,2) (3,2,0,1) (1,3,0,2)

    Between passing group 2 to group 3 same event will re occur.

    Still, such an approach will reduce repetitions.

    https://drive.google.com/file/d/102s4OHmnjeMfRpmxt-jDYrLon65z-HkU/view?usp=sharing

  • oosyrag,mrcgkh

    I agree, the best way is to use Advanced Random but I couldn't totally use it right.

    How am I supposed to use advanced random in my event sheet? If you share an example it would be good:)

  • Advanced Random could give you this. 0123 --> 3102

    But advanced random or other methods like Fisher Yates would not directly solve your problem. You said every 10 second a new event appear. But what will happen after 40 second. You need to re-shuffle it.

    In a situation like above, same events will appear at 70 and 80 seconds (1-1). As i explained before, even if you use advanced random the same event could happen. You need extra optimization for a problem like that.

    I also suggest my previous example

    https://drive.google.com/file/d/102s4OHmnjeMfRpmxt-jDYrLon65z-HkU/view?usp=sharing

    If you have 4 events , in every 40 seconds you may see the same events.

    If you have 100 events , in every 1000 seconds you may see the same event.

    So this is still a good approach.

  • I would suggest having a column on the array to store if the question could repeat or not. This way you can control which question could repeat.

    Just store 0 and 1 on a new column, and when this question apper on screen, compare if this column is = 0 if yes, remove this question from array, if 1 just keep it for next random.

  • I would suggest having a column on the array to store if the question could repeat or not. This way you can control which question could repeat.

    Just store 0 and 1 on a new column, and when this question apper on screen, compare if this column is = 0 if yes, remove this question from array, if 1 just keep it for next random.

    klabundee can u show me an example of it, please?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • > I would suggest having a column on the array to store if the question could repeat or not. This way you can control which question could repeat.

    >

    > Just store 0 and 1 on a new column, and when this question apper on screen, compare if this column is = 0 if yes, remove this question from array, if 1 just keep it for next random.

    klabundee can u show me an example of it, please?

    Yes. In the same example as I sent before, I just added a new column, and it stores 1 and 0. When it call for a question, if the column value = 0 it will remove the question/answers from the array.

    Here:

    mega.nz/file/98ABQKKZ

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