Syntax Errors and Assigned Value is wrong type
Author |
Message |
mattpk
|
Posted: Thu Mar 04, 2010 5:02 pm Post subject: 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)
Turing: |
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 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Thu Mar 04, 2010 5:05 pm Post subject: RE:Syntax Errors and Assigned Value is wrong type |
|
|
You're probably trying to put a string or real into an integer. |
|
|
|
|
![](images/spacer.gif) |
mattpk
|
Posted: Thu Mar 04, 2010 5:07 pm Post subject: 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 <= money1
then
money1 := money1 - buy
soldier1 := soldier1 + buy
put "You bought ", buy, " soldiers."
else
put "Not enough money, you buy nothing"
end if
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)
randint(luck2, 8, 10)
attack1 := luck1 / 10 * soldier1
attack2 := luck2 / 10 * 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
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 <= money2
then
money2 := money2 - buy
soldier2 := soldier2 + buy
put "You bought ", buy, " soldiers."
else
put "Not enough money, you buy nothing"
end if
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)
randint(luck2, 8, 10)
attack1 := luck1 / 10 * soldier1
attack2 := luck2 / 10 * soldier2
if attack2 > 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
|
|
|
|
|
|
![](images/spacer.gif) |
USEC_OFFICER
![](http://compsci.ca/v3/uploads/user_avatars/16624966004bb548179e82e.png)
|
Posted: Thu Mar 04, 2010 7:02 pm Post subject: Re: Syntax Errors and Assigned Value is wrong type |
|
|
Bam
Turing: | 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 <= money1
then
money1 := money1 - buy
soldier1 := soldier1 + buy
put "You bought ", buy, " soldiers."
else
put "Not enough money, you buy nothing"
end if
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)
randint(luck2, 8, 10)
attack1 := luck1 div 10 * soldier1
attack2 := luck2 div 10 * 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 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 <= money2
then
money2 := money2 - buy
soldier2 := soldier2 + buy
put "You bought ", buy, " soldiers."
else
put "Not enough money, you buy nothing"
end if
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)
randint(luck2, 8, 10)
attack1 := luck1 div 10 * soldier1
attack2 := luck2 div 10 * soldier2
if attack2 > 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. |
|
|
|
|
![](images/spacer.gif) |
|
|