Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to code a Lotto

So I'm new to coding and still in the very experimental stage with what I hope to do, I was wondering if it's possible to set up a lotto that draws from a list of flagged names. Basically certain actions would place these names into the pool and be drawn at random at some point, but I'm not at all sure how to manage that.

I've been mostly experimenting with sugar cube 2 so far.

Comments

  • edited February 2017
    Basically certain actions would place these names into the pool and be drawn at random at some point...

    That is incredibly vague; without knowing what your end goals are, or how/why you want to implement them, it's hard to know what exactly might be the best way. Are these names already in the code or will they be entered by a player? If the flagged names are included, does the end user choose the names or will you set them up with some sort of function?

    What you could do is create two arrays, one of which will contain all of the names, and another which will include the 'flagged' names. You can then use the random method to select a name from the latter list while still having both lists in the code.

    I'm not sure what conditions determine which names are flagged, so the code below will need that information added:
    <<set $names to ["John", "Sally", "Steve", "Kelly", "Paul", "Samatha"]>>
    <<set $flagged to []>>
    
    <<if (some conditions)>>
        <<set $flagged.push($names[0], $names[2], $names[5])>>
        /%this will add John (0), Steve (2), and Samantha (5) to the drawing%/
    <</if>>
    
    <<set $winner to $flagged.random()>>/%select a winner at random from the flagged array%/
    <<set $flagged to []>>/%reset the flagged array for the next drawing%/
    
    <<print $winner>> won the drawing!
    

    Depending on what you need to do, there's a good chance you won't necessarily need two arrays. If the flagging of the names needs to be based on user input, the <<checkbox>> macro is probably the best way to handle that.
  • edited February 2017
    I apologize, I know it's a rather vague request and I'm still working out the story itself, but it's more like an "if you do this, go here, or interact with this person" sort of deal that leads to them having their name into the pool largely automatically without direct player input.

    Since I'm still only just trying to figure out how to do the whole coding thing I initially tried to cobble something together based off flagging certain variables as "True" or adding the text names into it as things go along.

    That said what you put up helps greatly, so thank you. :)
  • @WritingDreamer
    Generally when you are first learning to code and are designing a new feature it is a good idea to forget about how you are going to program/code it and focus instead on describing in some detail what you want the new feature to do. Keep working on that detail until it clearly describes (the majority of) the new feature.

    Once you have that detailed description you can then break it down into it's (logical) individual components, doing this will help you understand what each part does, which in turn helps determine how to implement it using code.

    The above technique is used by many experienced programmers to design things.
Sign In or Register to comment.