Using "or" to trigger scripts

Talon

Hey coding peoples, think this is pretty simple, but not exactly sure how to do it...and searching for “OR” in the forums isn't going to narrow things down to much

I'd like for a script to check for one of a handful of attributes on the player before passing(Or not) Currently for testing I'm just using a basic test for what class a player has, this is set as player.class attribute.

I've tried this which seems logical

if (player.class = ("mage") or ("rogue")) {
msg (“hello there”)
}

I get an error of
“AndOrElement: Operation 'Or' is not defined for types 'Boolean' and 'String' “


Jay Nabonne

Try:

if (player.class = "mage" or player.class = "rogue") {
    msg (“hello there”)
}

You can only join boolean expressions with "and" and "or", which those above are - but you can also join boolean variables:

if (player.isDirty or player.isSick) {
    msg (“hello there”)
}

or even:

if (player.class = "mage" and not player.isSick) {
    msg (“hello there”)
}

hegemonkhan

as jay shows, each condition (aka, when separated by 'or' or 'and') must be a (full - oxymoronic but whatever) statement (think of Attribute syntax as a sentence, a 'statement' coding language terminology is the equivent to a 'sentence' human/english-language terminology):

(condition 1) or (condition 2)
(player.strength = 100) or (player.strength = 0) ---> works

'player.strength' would be the 'noun'
the '= 100/=0' would be the 'verb' (or maybe more technically the '=' is the verb and the '100/0' is the "subject/whatever the english terminology, meh-lol" --- of what is the verb's resulting effect)

so just as a sentence requires a 'noun' and a 'verb', so too must each of your conditions:

if (player.strength = 100 or player.strength = 0 or player.strength = 50 or player.strength = 25 or player.strength = 75)

the reason as jay explains, is that each condition must be able to be broken down into boolean 'false' or 'true' at the high-human level (which is thus further broken down into low-computer-near-electrical level bits '0' and '1', the machine code level, which the hardware/electricity components, ?transistors?, of having 'X voltage/current' or 'Y voltage current' is somehow associated/connected with the programming logical '1' or '0' - I still don't quite get this physics/engineering of how the association/connection occurs of the logical to the physical or vice-versa, almost understanding this stuff, but not quite fully yet). Everything in programming is ultimately a '0' or a '1' bit. Functions, Objects, etc, EVERYTHING is ultimately a '0' or a '1'. Thankfully, programming has been built up over the years and we got high level programming, which is much more human friendly and human capable than trying to do complex stuff at the low level (the low level requires multiple code lines compared to a single code line at the upper level, so... if you think you've coded a lot at the upper level... imagine converting all of that to coding at the low level... yikes... the high level has a lot more features too, but this does mean more overhead / more inefficiency, but usually the efficiency is insignificant to the other benefits of high level programming. Think of high level programming as ms word on your computer, compared to low level programming as having to write by hand in pen. We love the 'copy and paste' of ms word, we can't imagine having to write by hand in pen without 'copy and paste' or even without being able to 'erase', having to re-write the ENTIRE document if we need to change anything or if we mess up)


if you're interested:

any/all (1, 2, 3, a, b, c, A, B, C, !, @, #, etc etc etc) character/symbol (and also some few non-keyboard/input stuff/thingy-ies too: see the ASCII's 'Dec/decimal values from 0 to 31' --- the left column, as Dec/Decimal value of '32' is the start of the keyboard keys with the spacebar key) is associated a number value to/for it (the original USA-only language/symbols/characters ASCII: http://www.asciitable.com/ or the unicode, which just expands/adds-to the orginal USA's ASCII with the rest of the world's language/characters/symbols: http://unicode.org/charts/ / https://en.wikipedia.org/wiki/List_of_Unicode_characters), which is I think done as an 'instruction set' at the low level or is hard-coded/embedded into the hardware itself (The Operating System, OS, you buy and install/load does this for you --- it's one of the things the OS does, the OS is what connects, "allows the communication of", the computer hardware to the computer software, and vice-versa, and thus why all computers require an OS, unless you're a computer expert and you know how to code and use your computer at the hardware level yourself).

any number value, can be represented by the binary numbering system, and thus everything is a '0' or '1'.

the decimal system (0-9 digits):

each digit (starting from the right of course):

(powers of) base 10 = decimal

(digit: 0-9) * (10^0)
(digit: 0-9) * (10^1)
(digit: 0-9) * (10^2)
etc etc etc

53
(3) * (10^0 = 1) = 3
(5) * (10^1 = 10) = 50
50 + 3 = 53

100
(0) * (10^0 = 1) = 0
(0) * (10^1 = 10) = 0
(1) * (10^2 = 100) = 100
100 + 0 + 0 = 100

129
(9) * (10^0 = 1) = 9
(2) * (10^1 = 10) = 20
(1) * (10^2 = 100) = 100
100 + 20 + 9 = 129

----------------------

0000 = 0
0001 = 1
...
0009 = 9
0010 = 10
0011 = 11
...
0019 = 19
0020 = 20
...
0099 = 99
0100 = 100
0101 = 101
....
0110 = 110
....
0999 = 999
1000 = 1000

the binary numbering system (0-1 digits):

each digit (starting from the right of course):

(powers of) base 2 = decimal

(digit: 0-1) * (2^0)
(digit: 0-1) * (2^1)
(digit: 0-1) * (2^2)
etc etc etc

53 decimal
(powers of base 2: 2^0=1, 2^1=2, 2^2=4, 2^3=8, 2^4=16, 2^5=32, 2^6=64, 2^7=128, 2^8=256, 2^9=512, 2^10 = 1024, 2^11 = 2048, 2^12 = 4096, etc etc etc. How much RAM does your computer have? this is a binary value, find it: 2^N = your RAM)

2^6 = 64 ---> 53 - 64 ---> the 7th digit (from the right) is a '0'
2^5 = 32 ---> the 6th digit (from the right) is a '1'
53 - 32 = 21
2^4 = 16 ---> the 5th digit (from the right) is a '1'
21 - 16 = 5
2^3 = 8 ---> 5 - 8 ---> the 4th digit (from the right) is a '0'
2^2 = 4 ---> the 3rd digit (from the right) is a '1'
5 - 4 = 1
2^1 = 2 ---> the 2nd digit (from the right) is a '0'
2^0 = 1 ---> the rightmost digit is a '1'
1 - 1 - 0
=
110101 binary == 53 decimal

0110101 (= 110101) // just so you can match it up with the equation below (as you might get confused when looking at 110101 to the equation below, if you don't remember to look at it from right to left, so use the '0110101' so you can look at it from left to right)
[0 * (2^6)] + [1 * (2^5)] + [1 * (2^4)] + [0 * (2^3)] + [1* (2^2)] + [0 * (2^1)] + [1 * (2^0)] = 53
(2^5) + (2^4) + (2^2) + (2^0) = 53
(32) + (16) + (4) + (1) = 53

-------------------------------

(binary ~ decimal)

0000 ~ 0000 = 0
0001 ~ 0001 = 1
0010 ~ 0002 = 2
0011 ~ 0003 = 3
0100 ~ 0004 = 4
0101 ~ 0005 = 5
0110 ~ 0006 = 6
0111 ~ 0007 = 7
1000 ~ 0008 = 8

1 1011 ~ 53

1111 1111 ~ 255

1 0000 0000 ~ 256

here's the equivolent as a (well 2) sentence(s) of incorrect coding syntax (what you did, why you got the ERROR):

if (run 1 mile or run 4 mile)... ERROR: What is running 1 mile? What is running 4 miles?
if (bob run 1 mile or run 4 mile)... ERROR: What is running 4 miles?

unfortunately, in programming you can't do this (or if it can be done... usually it's not programmed in or it's just too much work or too complex, anyways, meh):

if [ (bob) and (run 1 mile or run 4 miles) ]
// math distribution: 'bob' is being applied correctly to 'run 1 mile' and to 'run 4 miles'
// if [ (5) * (4 or 7) ]
// 5 * 4 = 20
// or
// 5 * 7 = 35

the programming requires this (each condition is a full statement/expression), thus no distribution ability:

if [ (5 * 4) or (5 * 7) ]


many games, especially the old console games, have the '256' cutoff (0-255) (255 decimal = 1111 1111 binary = 8 bits = 1 byte) for various data/stats (if a value goes over 255, it's reset to: 0 or 0 + amount over 255, so for example, instead of having 300 strength, you'd have only 0 or 45 strength, which is not cool, a "bug" for the game player, as they went from having 255 strength to having only 0 or 45 strength, despite getting +45 strength which should be 300 strength not 0 or 45 strength!, but technically it's not a true bug - it's intentional to protect the entire game data/memory and/or how 'addition' operation actually works / is done/programmed at the low level: bit shifting/rotating, not going to get into trying to explain it however here. If you don't get the 0 or 45 strength with my example... programmer's coding error, as you're getting into data/memory you're not suppose to, messing ALL of it up, and/or also possibly enabling you power to do what you want, aka manipulate/change, with it, "hexidecimal:base 16 / hexeditor software" hacking)


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums