I'm finding it increasingly useful to use flags in my dialogue system. The latest example is I have a quest whereby the user has to go and collect 5 unique pieces of intel from various sources before going back to an NPC to complete the quest.
For example, at the end of an conversation where I want to give the user a new piece of intel: it would be great if I could do:
Variable[Intel] = Variable[Intel] | 1
Variable[Intel] = Variable[Intel] | 2
Variable[Intel] = Variable[Intel] | 4
Variable[Intel] = Variable[Intel] | 8
Variable[Intel] = Variable[Intel] | 16
(1, 2, 4, 8, 16 for the 1st to 5th bits of intel)
This bits not where I have the problem really, I have used this before where I write a script which runs after the conversation to OR a request sum to a requested variable.
However where I'm having trouble now is when I want to disable conversation paths if the user has that particular piece of intel. Something like:
Variable[Intel] & 1 == 0 could be an example condition to only allow that conversation path when the user doesn't have the first piece of intel. Again I've tried an alternate method for this, I have a script to go on my game objects which switches the whole conversation based on the condition of a variable, but it wouldn't be appropriate to use in this case.
There is another way, if I created 5 boolean variables and an integer counter variable, I could keep track in individual conversations and keep a total of how many bits of intel the user has received, but being able to use binary operators would make life so much easier. Is this sort of thing possible?
Using binary operators as conditions / scripts.
-
- Posts: 39
- Joined: Wed Sep 03, 2014 2:44 am
Using binary operators as conditions / scripts.
Hi Andrew,
Bitwise operators were introduced in Lua 5.2. The Dialogue System's default Lua implementation is LuaInterpreter, which conforms to the Lua 5.1 specs. If you have Unity Pro, you can switch to NLua, which conforms to Lua 5.2. Otherwise you'll have to use Booleans or register your own bitwise functions written in C#. If you write your own functions, please keep in mind that LuaInterpreter stores all numbers as doubles internally.
Bitwise operators were introduced in Lua 5.2. The Dialogue System's default Lua implementation is LuaInterpreter, which conforms to the Lua 5.1 specs. If you have Unity Pro, you can switch to NLua, which conforms to Lua 5.2. Otherwise you'll have to use Booleans or register your own bitwise functions written in C#. If you write your own functions, please keep in mind that LuaInterpreter stores all numbers as doubles internally.
-
- Posts: 39
- Joined: Wed Sep 03, 2014 2:44 am
Using binary operators as conditions / scripts.
Oh thats good news, I'll have a play with NLua Thank you!