When either player inputs their "attack type" in the combat system of a game I'm working on, it skips every "if" statement that calculates damage, and the result is consequently always zero.
The full executable code is here:
sync on
sync rate 100
dim melee(2)
dim defense(2)
dim hits(2)
dim equip(2)
dim weapon(4,3)
dim recoil(2)
dim atyp(2)
dim tbon#(2)
dim level(2)
melee(1)=10
melee(2)=10
defense(1)=10
defense(2)=10
hits(1)=100
hits(2)=100
equip(1)=4
equip(2)=1
weapon(1,1)=80
weapon(1,2)=30
weapon(1,3)=10
weapon(4,1)=50
weapon(4,2)=60
weapon(4,3)=30
level(1)=(melee(1)+defense(1)+hits(1)/10)/3
level(2)=(melee(2)+defense(2)+hits(2)/10)/3
tbon#(1)=1
tbon#(2)=1
do
cls
if recoil(1)<1
input "Player 1 1=Quick 2=Aggressive 3=Cautious : ",atyp(1)
if atyp(1)=1
rem a test block%%%%%%%%%%%%%%%%%%%%
print "hello"
sync
wait key
rem end of test block%%%%%%%%%%%%%%%
recoil(1)=(100-weapon(equip(1),1))*0.8
power=melee(1)*10+weapon(equip(1),2)
resist=(defense(2)*10+weapon(equip(2),3))*tbon#(2)
level#=level(1)
power#=power
resist#=resist
damage#=(((2 * level# / 5 + 2)*power#^2/resist#)/50+2)*(80+rnd(40))/100
damage=damage#
hits(2)=hits(2)-damage
tbon#(1)=1
endif
if atyp(1)=2
power=melee(1)*10+weapon(equip(1),2)*1.2
resist=(defense(2)*10+weapon(equip(2),3))*tbon#(2)
level#=level(1)
power#=power
resist#=resist
damage#=(((2 * level# / 5 + 2)*power#^2/resist#)/50+2)*(80+rnd(40))/100
damage=damage#
hits(2)=hits(2)-damage
recoil(1)=(100-weapon(equip(1),1))
tbon#(1)=1
endif
if atyp(1)=3
power=melee(1)*10+weapon(equip(1),2)
resist=(defense(2)*10+weapon(equip(2),3))*tbon#(2)
level#=level(1)
power#=power
resist#=resist
damage#=(((2 * level# / 5 + 2)*power#^2/resist#)/50+2)*(80+rnd(40))/100
damage=damage#
hits(2)=hits(2)-damage
recoil(1)=(100-weapon(equip(1),1))
tbon#(1)=1.2
endif
print "You did ",damage," damage! Your opponent has ",hits(2)," HP left."
print " "
sync
wait key
endif
recoil(1)=recoil(1)-1
if recoil(2)<1
input "Player 2 1=Quick 2=Aggressive 3=Cautious : ",atyp(2)
if atyp(2)=1
recoil(2)=(100-weapon(equip(2),1))*0.8
power=melee(2)*10+weapon(equip(2),2)
resist=(defense(1)*10+weapon(equip(1),3))*tbon#(1)
level#=level(2)
power#=power
resist#=resist
damage#=(((2 * level# / 5 + 2)*power#^2/resist#)/50+2)*(80+rnd(40))/100
damage=damage#
hits(2)=hits(2)-damage
tbon#(1)=1
endif
if atyp(2)=2
power=melee(2)*10+weapon(equip(2),2)*1.2
resist=(defense(1)*10+weapon(equip(1),3))*tbon#(1)
level#=level(2)
power#=power
resist#=resist
damage#=(((2 * level# / 5 + 2)*power#^2/resist#)/50+2)*(80+rnd(40))/100
damage=damage#
hits(1)=hits(1)-damage
recoil(2)=(100-weapon(equip(2),1))
tbon#(2)=1
endif
if atyp(2)=3
power=melee(2)*10+weapon(equip(2),2)
resist=(defense(1)*10+weapon(equip(1),3))*tbon#(1)
level#=level(2)
power#=power
resist#=resist
damage#=(((2 * level# / 5 + 2)*power#^2/resist#)/50+2)*(80+rnd(40))/100
damage=damage#
hits(1)=hits(1)-damage
recoil(2)=(100-weapon(equip(2),1))
tbon#(2)=1.2
endif
print "You did ",damage," damage! Your opponent has ",hits(2)," HP left."
print " "
sync
wait key
endif
recoil(2)=recoil(2)-1
sync
loop
This is an example of the troubling section:
sync on
sync rate 100
dim atyp(2)
input "Player 1 1=Quick 2=Aggressive 3=Cautious : ",atyp(1)
if atyp(1)=1
rem a test block%%%%%%%%%%%%%%%%%%%%
print "hello"
sync
wait key
rem end of test block%%%%%%%%%%%%%%%
rem some more code
endif
If you input "1" I want the code to print "hello" and wait for a key, but the program considers the "IF" statement false and continues.
Is this an issue with arrays or my syntax?
Thankyou,
Schnell