[SOLVED] Spawning Actors Based On A Configurable Percentage?
To give you the easiest explanation of the game in order to help you understand what I mean;
In sets of four (Can be upgraded in my shop) every 1.4 seconds (Can also be lowered in shop) Ore-Chunks will spawn at random locations on screen. So, 1.4 seconds -> four coal spawn in random places on screen for the player to collect. Ok so far? After the player earns enough points, they will then be able to unlock a new tier of ore, in this case, "iron". How can I make it so that, Iron will have.. lets say 10% chance of spawning once on screen (The other 3 "in the set of four i mentioned earlier" being coal). How can I make this happen, while ALSO allowing the players to eventually change this percentage? I.e: Upgraded the chance of higher tier ores? Seeing as how I will have several more than just coal and iron, is there a way to have a general increase in spawning for the higher tier ores? Will this be a hard task to accomplish? Not entirely sure. I have a few ideas in mind but these are massive walls in my head so Im curious if anyone lurking the forums has an easier solution to how I can, in short words, 1: Spawn an actor based on percentage (That can be configurable by the players) and 2: If its possible to make sort of a "Global increase" for higher tear ores. Thanks in advanced!
Comments
The random() function can be used for probability. A ten percent change is created by using Change Attribute game.random to random(1,10) and a rule that says If game.random<2, spawn. A 20% chance would be game.random<3, etc.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang Aha! I knew there had to be a simple solution, thanks for the tip!
@tatiang I am to assume I could generally add a "random" attribute for each ore in my game? Therefore when they buy said upgrade, I can make it change each of the ores of my choosing (in this case the higher up ones) to a better percentage? Correct?
Edit: Looking at the (1,10) chance you mentioned, I assume in place of "1" as a plain number, I should make a new integer which will take place of the actual number, so this way the player can change the integer which will ultimately up the chance? Im just assuming this will work, Ill hop in later to test it anyways
@SikkJewFro said:
The (1,10) represents the range the random number generator works on, so you'd be better off replacing the 10 with an attribute. So (1,5) would be a 20% chance, (1,100) would be a 1% chance, (1,3) would be a 33.33% chance . . . and so on.
You're on the right track. You would still use random(1,10) but the rule would be if game.random<game.percentage+1, spawn. The value of game.percentage could change (1 would be 10%, 2 would be 20%, 3 would be 30%, etc.).
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User