how to learn random skills

orochiadam

Gaming Hobo
Member
Joined
Nov 19, 2019
Messages
7
Reaction score
0
First Language
english
Primarily Uses
RM2k3
Perhaps My language is unclear each book there's a list of learnable spells you read a book by consuming it and learn from a list of 20 spells
Example Crimson book (fire spells)
1Fire Bolt
2Dragon Breath
3Demon Fire
4)Flaming Wings
5)Fire Seeds
6)Towering Inferno
7)Cremate
8)Flamethrower
9)Inferno
10)Waterfall of Flames
11)Molotov Cocktail
12)Hellfire
13)Flash
14)Flamenwaffer
15)Dragon Fire
16)Wings of Hell
17)Fireball
18)Incendiary Cloud
19)Napalm
20)Flames of Hell
 
Last edited:

Cherry

RM2k(3) Developer (English Version)
Developer
Joined
Apr 19, 2015
Messages
120
Reaction score
71
First Language
German
Primarily Uses
You would write a random value 1-20 into a variable and then do 20 conditional branches, if the variable is 1 you teach Fire Bolt, if it's 2 you teach Dragon Breath, and so on.

This gets a bit more complicated if you want to make sure the hero will only learn a skill they don't already know - this case I'd say the easiest way would be to put the whole thing in a loop, and instead of just teaching each skill you would use another condition inside each condition to check whether the skill was already learned, and only if no you teach it and break the loop. This way it would just try again and again random skills until it finds one that can be learned.

To avoid getting the game stuck in an infinite loop if all 20 skills are already known, you'd then add a condition before everything else where you basically nest 20 conditions that check for each skill, so only if all 20 are true (skills known), you would then show some message that there is nothing left to learn and exit.

Pseudocode:

Code:
if hero knows skill A
  if hero knows skill B
    if hero knows skill C
      ...
      ...
      ...
        if hero knows skill T
          show message: "nothing to learn"!
          end event processing
        : end
      ...
      ...
      ...
    : end
  : end
: end

label 1

change variable SKILL_NUM = random (1...20)

if SKILL_NUM == 1
  if hero knows skill A
    go to label 1
  : else
    teach hero skill A
  : end
: end

if SKILL_NUM == 2
  if hero knows skill B
    go to label 1
  : else
    teach hero skill B
  : end
: end

if SKILL_NUM == 3
  if hero knows skill C
    go to label 1
  : else
    teach hero skill C
  : end
: end

...
...
...

if SKILL_NUM == 20
  if hero knows skill T
    go to label 1
  : else
    teach hero skill T
  : end
: end
Here instead of a loop command and breaking the loop after teaching, I used a label at the start of the code to create the loop in order to make it shorter (because we can jump to it in one case and learn the skill in the other, instead of having an awkward empty case first and then both the breaking and the teaching in the "else").
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

does there exist a word for a state of being that is between "living" and (not "dead", but ...) "not living" .... does that make sense, or do I just sound like Im high for something :[ ?
Hope you are all fine today~
Moderators, you must have so much patience to be able to deal with everything. I mod in a server of sorts and today we just got a message, which, despite it's helpful constructive criticism, basically stated that all of the mods were jerks and that was the only reason our server was unlikeable. So, thank you, for having patience. You are appreciated! :kaoluv:
Haired slime? Trying some different styles of art. Maybe I can make some resources with this new kind of painting.......

Forum statistics

Threads
105,742
Messages
1,016,057
Members
137,426
Latest member
Brockhamptonmerch
Top