Using binary operators as conditions / scripts.
Posted: Wed Jan 07, 2015 2:41 am
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?
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?