Computer Science Canada

I'm Making A Text Based RPG And I Seem To Be Stumped

Author:  ProxyKaliber [ Thu Jun 08, 2017 9:11 am ]
Post subject:  I'm Making A Text Based RPG And I Seem To Be Stumped

What is it you are trying to achieve?

I am trying to get these functions working so that way I can make the combat system work more efficiently and when the story progresses I can just call upon the functions to make it easier to start the combat part.

What is the problem you are having?

I'm getting some errors that I'm not too sure about. It says that a "." is expected when I try to give a range for a Rand.Int or that I can only reference "Int" (when I try to use Rand.Int) in a post statement and I've never heard of Post statements...


Describe what you have tried to solve this problem

I have tried to move some functions around because maybe it's the order they'r in. I have a hunch that it could be my variables and the input that the function takes to make the output unless I'm missing something which I think I am... maybe it's right there (is it "result [something here]"?).


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

Turing:

% var character_class_num : string % (To ask for either "1", "2", or "3" as a simpler way for the user to select their class)
var character_name, name_of_character : string
var health_points, mana_points, gold_amount, defense_stat, attack_stat : int
var character_class, class_of_character : string
var health_new, mana_new, gold_new, defense_new, attack_new : int
var opp_health_points, opp_defense_stat, opp_attack_stat : int
var opp_health_new, opp_defense_new, opp_attack_new : int
var RNG_stat_select : int
var battle_start : boolean
var user_input : string

function generate_opp_stats (Rand.Int : int)
    if (battle_start = true) then
        opp_health_points := Rand.Int (85 .. 150)
        opp_defense_stat := Rand.Int (45 .. 65)
        opp_attack_stat := Rand.Int (30 .. 50)
    end if
end generate_opp_stats

function attack_option_1 (attack_stat : int)
    if (user_input = "Attack - Basic") then
        attack_new := attack_stat * 1
        opp_health_new := opp_health_points - ((attack_new / opp_health_points) * 100)
    end if
end attack_option_1

function attack_option_2 (attack_stat : int)
    if (user_input = "Attack - Heavy") then
        attack_new := attack_stat * 2
        opp_health_new := opp_health_points - ((attack_new / opp_health_points) * 100)
    end if
end attack_option_2

function heal_25_HP (health_points : int)
    if (user_input = "Item - Heal" and health_points < health_points - 25) then
        health_new := health_points + 25
    else
        put "Health is too full!"
    end if
end heal_25_HP

function debuff_opponent (user_input : int)
        RNG_stat_select : Rand.Int (1 .. 3)
    if (user_input = "Item - Debuff") then
        if (RNG_stat_select = 1) then
            opp_health_new := opp_health_points - 25
        elsif (RNG_stat_select = 2) then
            opp_attack_new := opp_attack_stat - 5
        elsif (RNG_stat_select = 3) then
            opp_defense_new := opp_defense_stat - 5)
        else
            put "***** ERROR *****"
        end if
    end if
end debuff_opponent

function defend_2_rounds (defense_stat : int)
    if (user_input = "Defend") then
        defense_new := defense_stat * 2
    end if
end defend_2_rounds

function battle_end (health_new : int)
    loop
        combat_input (user_input : string)
        exit when (health_new = 0 or opp_health_new = 0 or user_input = "Flee")
    end loop
end battle_end

function flee_in_shame (user_input : string)
    if (user_input = "Flee") then
        battle_end
    end if
end flee_in_shame

function combat_input (user_input : string)
    if (userInput = "Attack - Basic") then
        attack_option_1 (user_input)
    elsif (user_input = "Attack - Heavy") then
        attack_option_2 (user_input)
    elsif (user_input = "Item - Heal") then
        heal_25_HP (user_input)
    elsif (user_input = "Item - Debuff") then
        debuff_opponent (user_input)
    elsif (user_input = "Defend") then
        defend_2_rounds (user_input)
    elsif (user_input = "Flee") then
        flee_in_shame (user_input)
    else
        put "***** ERROR *****"
    end if
end combat_input


Please specify what version of Turing you are using

Turing 4.1.1

Author:  Insectoid [ Thu Jun 08, 2017 10:17 am ]
Post subject:  RE:I\'m Making A Text Based RPG And I Seem To Be Stumped

Rand.Int uses a comma, not periods.

Rand.Int (85, 150)

I can't test it right now but I have a feeling that fixing this might solve both of your error messages.

Author:  ProxyKaliber [ Fri Jun 09, 2017 9:36 am ]
Post subject:  Re: I'm Making A Text Based RPG And I Seem To Be Stumped

Thanks. I'm going to try that right now haha. I get tiny things like that confused.

Author:  ProxyKaliber [ Mon Jun 12, 2017 8:17 am ]
Post subject:  Re: I'm Making A Text Based RPG And I Seem To Be Stumped

Unfortunately that solved very little of the many errors I've been getting. I also logged on today for the second time to find that all of my progression has been deleted, either by computer error or my own it is too soon to assume because assuming makes an ass out ouf u and me. Anyways. I've got a lot to catch up with.

Author:  TokenHerbz [ Wed Aug 16, 2017 9:45 pm ]
Post subject:  RE:I\'m Making A Text Based RPG And I Seem To Be Stumped

Turing:

%%First thing i seen was your functions are wrong.
%% i got a slight feeling some copy pasting was done??

%%a functions need to return a value
function randNum : int %%%EXAMPLE HERE
    result Rand.Int(1 , 5) %%return value
end randNum

put randNum %%calls the random function which returns a RESULT

%%%%%%%%%%%example with params
function randNumRange (lowRange, highRange: int) : int   
    result Rand.Int(lowRange, highRange)
end randNumRange

put randNumRange(5,8) %%calls function with params


%%%%%%%%%%%%%%%%%%%%
%%procedures don't need to return a value if you want to "DO WORK"
%%normally i'd use classes, but for easy of understanding here
var player_hp := 15
var potion1 := 25
var potion2 := 50

%%normally you want to pass the "USER HEALING" so its universal
%%but we wont here
proc heal(var health_pot: int)
    player_hp += health_pot
end heal

%%USER USES HEALTH POTION
heal (potion2)
%%heal (user, potion_type) %%kind of what you want is this one
put player_hp


also i'd usually have the inputs in the main loops and have functions/procs that deal with it from there.

Author:  Dragon20942 [ Fri Sep 22, 2017 9:21 pm ]
Post subject:  RE:I\'m Making A Text Based RPG And I Seem To Be Stumped

I don't think Rand.Int can be introduced as a local variable. That might be the whole deal with the "post statement" since Rand.Int can only be "posted" as a value, but it cannot be assigned values itself.

This is the line in which I find the issue:

Turing:

function generate_opp_stats (Rand.Int : int)


: