#error with script

1 messages · Page 1 of 1 (latest)

lucid parrot
#

hi i was trying to make my character stop walking when the punching animations starts but i get this error :

(68,44): error CS1525: Invalid expression term 'bool'

here is the script

gleaming estuary
#

Look at the line with the error

lucid parrot
gleaming estuary
#

The error is telling you that bool is an invalid expression here. Why on earth did you write bool("StopWalking == false), as if it were a function?

lucid parrot
gleaming estuary
#

but why did you write bool(...)

#

that's not how if statements work

#

It's just if (a && b), not if (a && bool(b)), that makes no sense

lucid parrot
gleaming estuary
#

no, because you can't compare a string to true/false

#

and even if you could, it would be a pointless check. "StopWalking" cannot be equal to false. because it is equal to "StopWalking"

lucid parrot
gleaming estuary
#

??? use a bool

#

why do you not want to do that

lucid parrot
#

cuz u just said that i can't use a bool in that code

gleaming estuary
#

I didn't say "a bool", I said "bool", the literal usage of the keyword

lucid parrot
#

oh ok

gleaming estuary
#

this line is nonsense. bool is not a function

#

you can't call it like a function

lucid parrot
#

ok so i just need to check if StopWalking is false without using "bool" cuz it's not a function right?

gleaming estuary
#

well no because of the other thing I said

lucid parrot
#

oh

gleaming estuary
#

you're comparing completely unrelated things. it's as if you are picking up an orange and saying "is this equal to my name?", when such a question is meaningless. your name is not a fruit, and a fruit is not your name

#

similarly, a string is a variable that contains text
false is a boolean value

text != boolean

#

they are not comparable

lucid parrot
#

ok now i understeand

gleaming estuary
#

create a bool variable, set it to true/false when you need to, and check that

lucid parrot
#

but how can i tell the code to check if it's true or false i can't just make an if statement inside an if statement?

gleaming estuary
gleaming estuary
lucid parrot
gleaming estuary
#

but you don't need to, because you are using && already

#
if (conditionA)
{
    if (conditionB)
    {
        // code
    }
}

is exactly equal to

if (conditionA && conditionB)
{
    // code
}
lucid parrot
#

so i can just write this :

if (direction.magnitude >= 0.1f && "StopWalking")

gleaming estuary
#

no that's still a string

gleaming estuary
#

create a bool variable. bool stopWalking; or something
and then check if (direction.magnitude > 0.1f && !stopWalking)

lucid parrot
#

oh i just need to put a ! then

gleaming estuary
#

! means "not", so it will check the opposite is true.

if stopWalking is false, you presumably don't want to stop walking, and so !stopWalking gives you the opposite - true. this is true, the magnitude > 0.1 is true, the condition will execute

#

if it is true, the opposite is false. the fact it's false means it will not execute

lucid parrot
#

ok ty for the help

lucid parrot
fair sable
prisma sluice
lucid parrot
lucid parrot
prisma sluice
#

Just declare once in your code
bool StopWalking = false;

And whenever you want to change value do
StopWalking = true