Advertisement

RPG Text VB (Some Issues)

Started by February 19, 2015 05:27 PM
2 comments, last by JeremyB 9 years, 10 months ago

Hey,

I just watched Get Lamp the other day, wicked dock on the old adventure games. It's got members of infocom talking, fans, and others. They go over adventure, Zork, and some other stuff. It's pretty neat.

I decided to make an RPG modelled after a d20 style table top.

I've got a couple issues in my code though. Trying to track them down.

When my player picks a gender I get output for male twice no matter which gender they pick.

Somewhere along the line I get in an infinite loop which deosn't let me get to the last part of my code....

If you're too lazy to help find the loop I get caught in, maybe just have a peek at the gender selection code...

Gender Pick Code


 Case 2
                    'Pick Gender'
                    If hero.Gender = "" Then

                        While hero.Gender = ""

                            If command = "" Then

                                output_text.AppendText("It didn't come " + hero.return_pronounmod("his/her", "l") + " mind right away. Choose a gender: male or female." + vbNewLine)

                                Exit Sub
                            Else
                                '' Test for male as gender selection
                                For Each synonym As String In synonyms.male

                                    If Regex.IsMatch("\b" + command + "\b", synonym) Then

                                        hero.Gender = "male"
                                        output_text.AppendText("Yes, a male. He groaned a little from unknown pain. His body seared with a crushing numbness." + vbNewLine)

                                    End If
                                Next

                                '' Test for female as gender selection
                                For Each synonym As String In synonyms.female

                                    If hero.Gender = "" Then

                                        If Regex.IsMatch("\b" + command + "\b", synonym) Then

                                            hero.Gender = "female"
                                            output_text.AppendText("Yes, a female. She groaned a little from unknown pain. Her body seared with a crushing numbness." + vbNewLine)

                                        End If

                                    Else

                                    End If

                                Next

                            End If

                        End While

                        output_text.AppendText("Srengths, weaknesses, what were they? Press the enter button to roll stats." + vbNewLine)
                        playercreation.creationStep = 3
                        Exit Sub
                    Else

                        output_text.AppendText("Srengths, weaknesses, what were they? Press the enter button to roll stats." + vbNewLine)
                        playercreation.creationStep = 3

                    End If

Entire Bit


  Public Sub run_command()

        command = input_text.Text.ToLower
        input_text.Text = ""
        scrollbar.ScrollToBottom()

        If runOption = "new game" Then

            ''Start of new game.
            If playercreation.creationStep = 0 Then

                output_text.SelectAll()
                output_text.Selection.Text = ""

            End If

            Select playercreation.creationStep
                Case 0
                    output_text.AppendText("A pounding headache blocked all recognition of a name. Maybe it would come. It had to. Enter a name below." + vbNewLine + vbNewLine)
                    playercreation.creationStep = 1
                Case 1

                    While hero.Name = ""
                        // Check entered name for empty value
                        If command = "" Then

                            output_text.AppendText("Thinking harder might have helped. Please enter a name." + vbNewLine)

                            Exit Sub

                            // Check entered name for numbers.
                        ElseIf command.Length > 12 Then

                            output_text.AppendText("No, it can't be, it must have been less than 12 letters..." + vbNewLine)
                            Exit Sub
                            '' Check for whitespace
                        ElseIf Regex.IsMatch(command, "\s") Then

                            output_text.AppendText("No, it was only one word...")
                            Exit Sub
                            '' Check for numbers
                        ElseIf Regex.IsMatch(command, numberPattern) Then

                            output_text.AppendText("No, there were no numbers in it." + vbNewLine)

                            Exit Sub
                        ElseIf Regex.IsMatch(command, "\W") Then

                            output_text.AppendText("It couldn't have been. Surely there were no strange symbols in it." + vbNewLine)
                            Exit Sub
                        Else

                            '' The entered name is accepted.
                            hero.Name = command

                        End If

                    End While

                    output_text.AppendText("Gender raced through " + hero.Name + "'s " + "mind. Male or female?" + vbNewLine)
                    playercreation.creationStep = 2
                Case 2
                    'Pick Gender'
                    If hero.Gender = "" Then

                        While hero.Gender = ""

                            If command = "" Then

                                output_text.AppendText("It didn't come " + hero.return_pronounmod("his/her", "l") + " mind right away. Choose a gender: male or female." + vbNewLine)

                                Exit Sub
                            Else
                                '' Test for male as gender selection
                                For Each synonym As String In synonyms.male

                                    If Regex.IsMatch("\b" + command + "\b", synonym) Then

                                        hero.Gender = "male"
                                        output_text.AppendText("Yes, a male. He groaned a little from unknown pain. His body seared with a crushing numbness." + vbNewLine)

                                    End If
                                Next

                                '' Test for female as gender selection
                                For Each synonym As String In synonyms.female

                                    If hero.Gender = "" Then

                                        If Regex.IsMatch("\b" + command + "\b", synonym) Then

                                            hero.Gender = "female"
                                            output_text.AppendText("Yes, a female. She groaned a little from unknown pain. Her body seared with a crushing numbness." + vbNewLine)

                                        End If

                                    Else

                                    End If

                                Next

                            End If

                        End While

                        output_text.AppendText("Srengths, weaknesses, what were they? Press the enter button to roll stats." + vbNewLine)
                        playercreation.creationStep = 3
                        Exit Sub
                    Else

                        output_text.AppendText("Srengths, weaknesses, what were they? Press the enter button to roll stats." + vbNewLine)
                        playercreation.creationStep = 3

                    End If
                Case 3

                    output_text.SelectAll()
                    output_text.Selection.Text = ""

                    //Rolling of the stats.
                    hero.Str = roller.roll_dice("d6", 3)
                    roller.Roll = 0
                    hero.Wis = roller.roll_dice("d6", 3)
                    roller.Roll = 0
                    hero.Int = roller.roll_dice("d6", 3)
                    roller.Roll = 0
                    hero.Dex = roller.roll_dice("d6", 3)
                    roller.Roll = 0
                    hero.Con = roller.roll_dice("d6", 3)
                    roller.Roll = 0
                    hero.Cha = roller.roll_dice("d6", 3)
                    roller.Roll = 0

                    output_text.AppendText("Strength: " + hero.Str.ToString() + vbNewLine + vbNewLine)
                    output_text.AppendText("Wisdom: " + hero.Wis.ToString() + vbNewLine)
                    output_text.AppendText("Inteligence: " + hero.Int.ToString() + vbNewLine)
                    output_text.AppendText("Dexterity: " + hero.Dex.ToString() + vbNewLine)
                    output_text.AppendText("Constitution: " + hero.Con.ToString() + vbNewLine)
                    output_text.AppendText("Charisma: " + hero.Cha.ToString() + vbNewLine)

                    output_text.AppendText("Do you like these stats? No, or roll, to re-roll. Yes to keep." + vbNewLine)
                    playercreation.creationStep = 4
                Case 4
                    // Get response for stats
                    If command = "no" Or command = "n" Or command = "roll" Or command = "rol" Or command = "reroll" Or command = "re-roll" Then

                        playercreation.creationStep = 3
                        run_command()

                    ElseIf command = "yes" Or command = "y" Or command.Contains("keep") Then

                        playercreation.creationStep = 5
                        run_command()
                        output_text.AppendText("Add 1 bonus point to any stat: Strength, Wisdom, Intelligence, Dexterity, Contitution, Charisma." + vbNewLine)

                    Else

                        output_text.AppendText("Please type yes to keep the current stats or, no to re-roll." + vbNewLine)

                    End If
                Case 5


                    If command = "" Then

                        output_text.AppendText("Please choose a stat to add a bonus point to." + vbNewLine)

                    Else

                        Select Case command
                            Case "Strength", "str"
                                If hero.Str < 18 Then

                                    hero.Str = hero.Str + 1
                                    playercreation.addedBonus = True
                                    output_text.AppendText("Added 1 point to strength." + vbNewLine)
                                    playercreation.creationStep = 6
                                    run_command()
                                Else

                                    output_text.AppendText("18 is the maximum score for strength." + vbNewLine)

                                End If
                            Case "wisdom", "wis"
                                If hero.Wis < 18 Then

                                    hero.Wis = hero.Wis + 1
                                    playercreation.addedBonus = True
                                    output_text.AppendText("Added 1 point to wisdom." + vbNewLine)
                                    playercreation.creationStep = 6
                                    run_command()
                                Else
                                    output_text.AppendText("18 is the maximum score for wisdom." + vbNewLine)
                                End If
                            Case "intelligence", "int"
                                If hero.Int < 18 Then

                                    hero.Int = hero.Int + 1
                                    playercreation.addedBonus = True
                                    output_text.AppendText("Added 1 point to intelligence." + vbNewLine)
                                    playercreation.creationStep = 6
                                    run_command()
                                Else
                                    output_text.AppendText("18 is the maximum score for intelligence." + vbNewLine)
                                End If
                            Case "dexterity", "dex"
                                If hero.Dex < 18 Then

                                    hero.Dex = hero.Dex + 1
                                    playercreation.addedBonus = True
                                    output_text.AppendText("Added 1 point to dexterity." + vbNewLine)
                                    playercreation.creationStep = 6
                                    run_command()
                                Else
                                    output_text.AppendText("18 is the maximum score for dexterity." + vbNewLine)
                                End If
                            Case "constitution", "con"
                                If hero.Con < 18 Then

                                    hero.Con = hero.Con + 1
                                    playercreation.addedBonus = True
                                    output_text.AppendText("Added 1 point to constitution." + vbNewLine)
                                    playercreation.creationStep = 6
                                    run_command()
                                Else
                                    output_text.AppendText("18 is the maximum score for constitution." + vbNewLine)
                                End If
                            Case "charisma", "cha"
                                If hero.Cha < 18 Then

                                    hero.Con = hero.Con + 1
                                    playercreation.addedBonus = True
                                    output_text.AppendText("Added 1 point to charisma." + vbNewLine)
                                    playercreation.creationStep = 6
                                    run_command()
                                Else
                                    output_text.AppendText("18 is the maximum score for charisma." + vbNewLine)
                                End If
                        End Select

                    End If
                Case 6

                    If playercreation.addedBonus = False Then

                        playercreation.creationStep = 5
                        run_command()

                    End If

                    ''Choose player class.

                    output_text.AppendText("What path did " + hero.Name + " follow? There were many: cleric, fighter, sorcerer, thief." + vbNewLine)
                    playercreation.creationStep = 7

                Case 7

                    While hero.CharClass = ""

                        If command = "" Then

                            output_text.AppendText("Choose a class." + vbNewLine)

                        ElseIf command = "cleric" Or command = "c" Then

                            If hero.Wis > 9 Then

                                hero.CharClass = "cleric"
                                output_text.AppendText("Yes, " + hero.return_pronounmod("he/she", "l") + " was a healer." + vbNewLine)
                                Exit Sub

                            Else

                                output_text.AppendText(hero.Name + "'s " + "wisdom score is too low to be a cleric.")

                            End If

                        ElseIf command = "fighter" Or command = "f" Then

                            If hero.Str > 9 Then

                                hero.CharClass = "fighter"
                                output_text.AppendText("Yes, " + hero.return_pronounmod("he/she", "l") + " was a warrior." + vbNewLine)
                                Exit Sub

                            Else

                                output_text.AppendText(hero.Name + "'s " + "strength is too low to be a fighter.")

                            End If
                        ElseIf command = "sorcerer" Or command = "s" Then

                            If hero.Int > 9 Then
                                hero.CharClass = "sorcerer"
                                output_text.AppendText("Yes, " + hero.return_pronounmod("he/she", "l") + " was trained in the arcane arts." + vbNewLine)
                                Exit Sub
                            Else
                                output_text.AppendText(hero.Name + "'s " + "intelligence was too low to be a sorcerer.")
                            End If

                        ElseIf command = "thief" Or command = "t" Then

                            If hero.Dex > 9 Then
                                hero.CharClass = "thief"
                                output_text.AppendText("Yes, " + hero.return_pronounmod("he/she", "l") + " was a cunning thief." + vbNewLine)
                                Exit Sub
                            Else
                                output_text.AppendText(hero.Name + "'s " + "Dexterity is too low to be a thief.")
                            End If

                        End If
                    End While

                    playercreation.creationStep = 7
                    run_command()
                Case 7
                    // Set the player's expirience bonus
                    MsgBox("Creation Step: " + playercreation.creationStep)
                    Select Case hero.CharClass
                        Case "cleric"
                            Select Case hero.Wis
                                Case 13
                                    hero.ExpBonus = 0.05
                                    output_text.AppendText("Gains 5% bonus to exp in battle.")
                                Case 16 - 18
                                    hero.ExpBonus = 0.1
                                    output_text.AppendText("Gains 10% bonus to exp in battle.")
                            End Select
                        Case "fighter"
                            Select Case hero.Str
                                Case 13
                                    hero.ExpBonus = 0.05
                                    output_text.AppendText("Gains 5% bonus to exp in battle.")
                                Case 16 - 18
                                    hero.ExpBonus = 0.1
                                    output_text.AppendText("Gains 10% bonus to exp in battle.")
                            End Select
                        Case "sorcerer"
                            Select Case hero.Int
                                Case 13
                                    hero.ExpBonus = 0.05
                                    output_text.AppendText("Gains 5% bonus to exp in battle.")
                                Case 16 - 18
                                    hero.ExpBonus = 0.1
                                    output_text.AppendText("Gains 10% bonus to exp in battle.")
                            End Select
                        Case "theif"
                            Select Case hero.Dex
                                Case 13
                                    hero.ExpBonus = 0.05
                                    output_text.AppendText("Gains 5% bonus to exp in battle.")
                                Case 16 - 18
                                    hero.ExpBonus = 0.1
                                    output_text.AppendText("Gains 10% bonus to exp in battle.")
                            End Select
                            playercreation.creationStep = 8
                        Case 8
                            // Set Players level, base attack bonus = 1, hit dice, and roll for hp.
                            // Set Players save and throws, Set skill points, set amount of weapon feats
                            // Set special  abilities, set equipment restrictions
                            Select Case hero.CharClass
                                Case "cleric"
                                    hero.Level = 1
                                    hero.HitDice = "1d6"
                                    roller.roll_dice("1d6", 1)
                                    hero.Hp = roller.Roll
                                    roller.Roll = 0
                                    hero.BaseAttackBonus = 1
                                    hero.SkillPoints = 4
                                    hero.WeaponFeatsAvailable = 2
                                    hero.add_special_ability("turn undead")
                                    hero.add_equipment_restriction("organic only")
                                    hero.add_savingthrow("death ray/poison", 11)
                                    hero.add_savingthrow("magic wands", 12)
                                    hero.add_savingthrow("peralysis/petrify", 14)
                                    hero.add_savingthrow("breath weapon", 16)
                                    hero.add_savingthrow("rod / staff / spell", 15)
                                Case "fighter"
                                    hero.Level = 1
                                    hero.HitDice = "1d8"
                                    roller.roll_dice("1d8", 1)
                                    hero.Hp = roller.Roll
                                    roller.Roll = 0
                                    hero.BaseAttackBonus = 1
                                    hero.SkillPoints = 4
                                    hero.WeaponFeatsAvailable = 4
                                    hero.add_equipment_restriction("none")
                                    hero.add_savingthrow("death ray/poison", 12)
                                    hero.add_savingthrow("magic wands", 13)
                                    hero.add_savingthrow("peralysis/petrify", 14)
                                    hero.add_savingthrow("breath weapon", 15)
                                    hero.add_savingthrow("rod / staff / spell", 16)
                                Case "sorcerer"
                                    hero.Level = 1
                                    hero.HitDice = "1d4"
                                    roller.roll_dice("1d4", 1)
                                    hero.Hp = roller.Roll
                                    roller.Roll = 0
                                    hero.BaseAttackBonus = 1
                                    hero.SkillPoints = 4
                                    hero.WeaponFeatsAvailable = 2
                                    hero.add_equipment_restriction("small")
                                    hero.add_savingthrow("death ray/poison", 13)
                                    hero.add_savingthrow("magic wands", 14)
                                    hero.add_savingthrow("peralysis/petrify", 13)
                                    hero.add_savingthrow("breath weapon", 16)
                                    hero.add_savingthrow("rod / staff / spell", 15)
                                Case "thief"
                                    hero.Level = 1
                                    hero.HitDice = "1d4"
                                    roller.roll_dice("1d4", 1)
                                    hero.Hp = roller.Roll
                                    roller.Roll = 0
                                    hero.BaseAttackBonus = 1
                                    hero.SkillPoints = 4
                                    hero.WeaponFeatsAvailable = 2
                                    hero.add_equipment_restriction("one handed")
                                    hero.add_special_ability("sneak attack")
                                    hero.add_special_ability("open locks")
                                    hero.add_special_ability("find traps")
                                    hero.add_special_ability("remove traps")
                                    hero.add_special_ability("pick pockets")
                                    hero.add_savingthrow("death ray/poison", 12)
                                    hero.add_savingthrow("magic wands", 13)
                                    hero.add_savingthrow("peralysis/petrify", 14)
                                    hero.add_savingthrow("breath weapon", 15)
                                    hero.add_savingthrow("rod / staff / spell", 16)
                            End Select
                            playercreation.creationStep = 9
                    End Select
                    run_command()
                Case 9
                    // Pick weapon feats
                    output_text.AppendText("What weapons was " + hero.Name + " skilled in?" + vbNewLine _
                                           + "Choose " + hero.WeaponFeatsAvailable + " from the list below.")

                    // This ends player creation
            End Select
            //End Check for if new game run option
        ElseIf runOption = "load game" Then
            // Start of load game

        End If

    End Sub

Thanks,

Jeremy.

I've done a little upkeep. I had to set my command to nothing periodically because I call my game function from within the game funcion. Had to be sure the previous value wasn't being run... I think I tracked down the problem in my gender slecetion. Think it's the regex, but i'm not sure.

If I type girl, or boy, I can seem to pick either gender find..

If I type male, or female, it seems to be getting confused.

"/bword/b" <- Is this the right regex for matching an exact word?


 Case 2
                    'Pick Gender'

                    If hero.Gender = "" Then

                        While hero.Gender = ""

                            If command = "" Then

                                output_text.AppendText("It didn't come " + hero.return_pronounmod("his/her", "l") + " mind right away. Choose a gender: male or female." + vbNewLine)
                                command = ""
                                Exit Sub
                            Else
                                '' Test for male as gender selection
                                For Each synonym As String In synonyms.male

                                    If Regex.IsMatch("\b" + command + "\b", synonym) Then

                                        hero.Gender = "male"
                                        output_text.AppendText("Yes, a male. He groaned a little from unknown pain. His body seared with a crushing numbness." + vbNewLine)
                                        Exit While
                                    End If
                                Next

                                '' Test for female as gender selection
                                For Each synonym As String In synonyms.female

                                    If hero.Gender = "" Then

                                        If Regex.IsMatch("\b" + command + "\b", synonym) Then

                                            hero.Gender = "female"
                                            output_text.AppendText("Yes, a female. She groaned a little from unknown pain. Her body seared with a crushing numbness." + vbNewLine)

                                        End If

                                    Else
                                        command = ""
                                        Exit While
                                    End If

                                Next

                            End If

                        End While

                        output_text.AppendText("Srengths, weaknesses, what were they? Press the enter button to roll stats." + vbNewLine)
                        playercreation.creationStep = 3
                        command = ""

                    Else

                        output_text.AppendText("Srengths, weaknesses, what were they? Press the enter button to roll stats." + vbNewLine)
                        playercreation.creationStep = 3

                    End If
Advertisement

Maybe try \Wword\W ? You could also make your own text parser.

Hey,

Thanks. I just notice regex was overkill for this. Straight = works here, and .contains if I want to add a little more flexability.

I'm gonna write a text parser for actual gameplay, but didn't think it would fit character creation, but I'm probably missing somesthing in understanding :)

This topic is closed to new replies.

Advertisement