Jump to content

BSL:Manual: Difference between revisions

753 bytes added ,  1 November 2017
BSL subtraction operator can be very tricky!
(BSL subtraction operator can be very tricky!)
Line 350: Line 350:
| Gives the result of subtracting the second number from the first.
| Gives the result of subtracting the second number from the first.
|}
|}
Subtraction operator can be very tricky in BSL! For instance what do you think the following code will display?
if(5-6 eq -1){
    dmsg("-1");
}
else{
    dmsg("NOT -1");
}
The above displays "NOT -1", why? Because for the operator "-" to work correctly you need to have a space between it an the numbers being subtracted otherwise it may return unexpected results!
So to fix the code above you should write it like this:
if(5 - 6 eq -1){
    dmsg("-1");
}
else{
    dmsg("NOT -1");
}
The above displays "-1".
Or you can use always Sum operator which doesn't suffer from this issue, just add the negative number and it will work as subtraction:
if(5+-6 eq -1){
    dmsg("-1");
}
else{
    dmsg("NOT -1");
}
The above displays "-1".


Note that there is no multiplication or division. Bungie West was only concerned with creating enough scripting power to drive Oni, and they did not need "higher math" for this. See [[#Data types|Data types]] to learn the details of how math works between different data types.
Note that there is no multiplication or division. Bungie West was only concerned with creating enough scripting power to drive Oni, and they did not need "higher math" for this. See [[#Data types|Data types]] to learn the details of how math works between different data types.
489

edits