
-----------------------------------
mattpk
Thu Mar 04, 2010 5:02 pm

Syntax Errors and Assigned Value is wrong type
-----------------------------------
What is it you are trying to achieve?
I am trying to create a turn-based battle system


What is the problem you are having?
Syntax Errors and Assigned Value is wrong type

Describe what you have tried to solve this problem
I tried to replace parts of code into variables


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)



put "Would you like to attack, pillage, or nothing. (type in attack, pillage, or nothing) " ..
        get choose

        if choose = "attack"
                then
            randint(luck1, 8, 10) / 10
            randint(luck2, 8, 10) / 10
            attack1 := luck1 * soldier1
            attack2 := luck2 * soldier2
            if attack1 > attack2
                    then
                put "You succeed in attacking. You win ", round (money2 / 2), " cash."
                money1 := round (money1 + (money2 / 2))
                money2 := round (money2 / 2)
            else
                put "You fail the attack. You lose ", round (money1 / 2), " cash."
                money1 := round (money1 / 2)
                money2 := round (money2 + (money1 / 2))
            end if


            soldier1 := attack1 - (attack2 / 2)
            soldier2 := attack2 - (attack1 / 2)
            put "You suffered ", attack2 / 2, " losses, and killed ", attack1 / 2, " soldiers."

        end if



Please specify what version of Turing you are using
Newest version

-----------------------------------
Insectoid
Thu Mar 04, 2010 5:05 pm

RE:Syntax Errors and Assigned Value is wrong type
-----------------------------------
You're probably trying to put a string or real into an integer.

-----------------------------------
mattpk
Thu Mar 04, 2010 5:07 pm

RE:Syntax Errors and Assigned Value is wrong type
-----------------------------------
[code]
var name1, name2, choose : string
var money1, money2, buy, income1, income2, attack1, attack2, luck1, luck2 : int
var soldier1, soldier2 : int

begin
    money1 := 100
    money2 := 100
    soldier1 := 0
    soldier2 := 0
    income1 := 10
    income2 := 10
    put "Type in player 1's name: " ..
    get name1
    put "Type in player 2's name: " ..
    get name2
    put ""
    put "War: ", name1, " against ", name2

    loop
        put name1, "'s turn!"
        put "Your income is ", income1, " . You recieve the income."
        money1 := money1 + income1
        put "You have ", money1, " cash currently, and ", soldier1, " soldiers."
        put "How many soldiers will you buy? 1 cash per soldier"
        get buy
        if buy  attack2
                    then
                put "You succeed in attacking. You win ", round (money2 / 2), " cash."
                money1 := round (money1 + (money2 / 2))
                money2 := round (money2 / 2)
            else
                put "You fail the attack. You lose ", round (money1 / 2), " cash."
                money1 := round (money1 / 2)
                money2 := round (money2 + (money1 / 2))
            end if


            soldier1 := attack1 - (attack2 / 2)
            soldier2 := attack2 - (attack1 / 2)
            put "You suffered ", attack2 / 2, " losses, and killed ", attack1 / 2, " soldiers."

        end if

        cls


        put name2, "'s turn!"
        put "Your income is ", income2, " . You recieve the income."
        money2 := money2 + income2
        put "You have ", money2, " cash currently, and ", soldier2, " soldiers."
        put "How many soldiers will you buy? 1 cash per soldier"

        get buy
        if buy  attack1
                    then
                put "You succeed in attacking. You win ", round (money1 / 2), " cash."
                money2 := round (money2 + (money1 / 2))
                money1 := round (money1 / 2)
            else
                put "You fail the attack. You lose ", round (money2 / 2), " cash."
                money2 := round (money2 / 2)
                money1 := round (money1 + (money2 / 2))
            end if


            soldier1 := attack1 - (attack2 / 2)
            soldier2 := attack2 - (attack1 / 2)
            put "You suffered ", attack1 / 2, " losses, and killed ", attack2 / 2, " soldiers."

        end if
        cls

    end loop

end
[/code]

-----------------------------------
USEC_OFFICER
Thu Mar 04, 2010 7:02 pm

Re: Syntax Errors and Assigned Value is wrong type
-----------------------------------
Bam

 var name1, name2, choose : string 
var money1, money2, buy, income1, income2, attack1, attack2, luck1, luck2 : int 
var soldier1, soldier2 : int 

begin 
    money1 := 100 
    money2 := 100 
    soldier1 := 0 
    soldier2 := 0 
    income1 := 10 
    income2 := 10 
    put "Type in player 1's name: " .. 
    get name1 
    put "Type in player 2's name: " .. 
    get name2 
    put "" 
    put "War: ", name1, " against ", name2 

    loop 
        put name1, "'s turn!" 
        put "Your income is ", income1, " . You recieve the income." 
        money1 := money1 + income1 
        put "You have ", money1, " cash currently, and ", soldier1, " soldiers." 
        put "How many soldiers will you buy? 1 cash per soldier" 
        get buy 
        if buy  attack2 
                    then 
                put "You succeed in attacking. You win ", round (money2 / 2), " cash." 
                money1 := round (money1 + (money2 / 2)) 
                money2 := round (money2 / 2) 
            else 
                put "You fail the attack. You lose ", round (money1 / 2), " cash." 
                money1 := round (money1 / 2) 
                money2 := round (money2 + (money1 / 2)) 
            end if 


            soldier1 := attack1 - (attack2 div 2) 
            soldier2 := attack2 - (attack1 div 2) 
            put "You suffered ", attack2 / 2, " losses, and killed ", attack1 / 2, " soldiers." 

        end if 

        cls 


        put name2, "'s turn!" 
        put "Your income is ", income2, " . You recieve the income." 
        money2 := money2 + income2 
        put "You have ", money2, " cash currently, and ", soldier2, " soldiers." 
        put "How many soldiers will you buy? 1 cash per soldier" 

        get buy 
        if buy  attack1 
                    then 
                put "You succeed in attacking. You win ", round (money1 / 2), " cash." 
                money2 := round (money2 + (money1 / 2)) 
                money1 := round (money1 / 2) 
            else 
                put "You fail the attack. You lose ", round (money2 / 2), " cash." 
                money2 := round (money2 / 2) 
                money1 := round (money1 + (money2 / 2)) 
            end if 


            soldier1 := attack1 - (attack2 div 2) 
            soldier2 := attack2 - (attack1 div 2) 
            put "You suffered ", attack1 / 2, " losses, and killed ", attack2 / 2, " soldiers." 

        end if 
        cls 

    end loop 

end 

Use div instead of / next time. / is for real vars.

Finding losses needs work (Subtract the number of soldiers by attack1 etc etc) The way you have it doesn't work. Also you can have less than zero soldiers.
