I have a agent "client" which contain 3 variables (all are initially false)
var_puttingFreeService
var_massageService
var_simulatorService
Now in the Main, I create an "event" which repeat in every 1 minute.
This event check if wait.size > 1 and any service is empty, then free the first agent from "wait" if all the above mentioned variable values are false for this agent.
But i am getting "NullPointerException" error even though the wait block is not empty.
Kindly let me know where I am making mistake.
what you need to understand is that
false && false || true || false
is true
you need to use parenthesis appropriately and the && takes precence over the ||
so you should do
if (wait.size()>1 && (delay1.size()==0 || delay2.size()==0))
you see the difference?
Related
I have the following 2 rules in my system. I am using 7.73.0. It is being run in a stateful session.
Rule 11 will fire but Rule 10 is not fired as a result of Rule 11. I would expect rule 11 to fire and then rule 10 because of the update statement.
I have debugged my code with a breakpoint on the setValue("A") in rule 11 and see that the method is being called and the value is set properly.
Can anyone tell me why rule 10 will not fire as a result of the update statement?
rule "MYRULES_10"
when
prod : Product(sku != "1")
$txt1 : TextOption(sku == "mm", value == "A")
then
prod.setOptionEnabled( "to2", false, "Not available rule 10" );
end
// rule values at B11, header at B5
rule "MYRULES_11"
when
prod : Product(sku != "1")
$opt1 : TextChoiceOption(sku == "mt")
exists (OptionValue(optionValueValue in ("val1")) from $opt1.value)
$txt1 : TextOption(sku == "mm")
then
$txt1.setValue("A"); update($txt1);
end
additional info:
If I fireAllRules on the session immediately after the initial fireAllRules, Rule 10 still will not fire.
If I take the result of the first stateful session and put all the facts into a second session and fireAllRules then rule 10 is fired and then rule 11 is fired.
If I put the fact in initially with fact mm having value A then rule 10 fires first and then rule 11 will fire.
Are you using a Stateless Session or Sequential Mode for your session? If yes, then this is the expected behaviour. https://docs.drools.org/8.31.0.Final/drools-docs/docs-website/drools/rule-engine/index.html#phreak-sequential-mode-con_rule-engine
Another option is that property reactivity is now working as expected because you are using the discouraged update() function to let Drools know about the modification of your facts. Try to use modify() instead:
...
then
modify($txt1){
setValue("A")
}
end
My if statement is not working, in other words it's not wanting to detect player scores. I've also tried checking if it exists.
Here is the whole script:
local price = script.Parent.Price.Value
local item = script.Parent.Price.Value
local db = true
local function buy(player)
local itemName = game.ServerStorage.GravityCoil:Clone()
print("got to click detecting")
if player:FindFirstChild("leaderstats").Tix.Value >= 5 then
print("checked price")
db = false
player.leaderstats.Tix.Value = player.leaderstats.Tix.Value - price
itemName.Parent = player.Backpack
print("gave item")
wait(.10)
db = true
end
end
script.Parent.ClickDetector.MouseClick:Connect(buy)
But we need to focus on one part,
if player:FindFirstChild("leaderstats").Tix.Value >= 5 then
print("checked price")
db = false
player.leaderstats.Tix.Value = player.leaderstats.Tix.Value - price
itemName.Parent = player.Backpack
print("gave item")
wait(.10)
db = true
There are no errors, warnings, anything in the console. I can't pinpoint the problem, I've joined discord servers, I've looked at roblox forums, I just can't find a solution to this problem! So please, if you have 30 minutes just to look at this and try to post an answer, I will praise you. Have a great day.
I suggest removing the FindFirstChild as leaderstats should already exist in player so there is no need to check for it. Also check if your greater sign is correct as you could have meant to put a lesser sign which resulted in the if statement not working.
None of it's working. Can you please help. This is in Roblox Studio.
local Time = math.floor (game.Lighting:GetMinutesAfterMidnight(480/60))
local intakeAlert = game.StarterGui.Main.IntakeAlert
local prisonerCount = game.ReplicatedStorage.NumPrisoners
local intake = game.ReplicatedStorage.PrisonerIntake -- This is the prisoner intake status
while wait() do
if Time == 8 then -- Checks if it is 8 hours after midnight.
print("Prison Bus Arriving.")
intakeAlert.Visible = true
wait(2)
intakeAlert.Visible = false
end
end
After reading your code, the reason I can say that the reason it is not running is because of this line of code:
if Time == 8 then -- Checks if it is 8 hours after midnight.
The main reason is probably your time variable.
local Time = math.floor (game.Lighting:GetMinutesAfterMidnight(480/60))
First things first, GetMinutesAfterMidnight() doesn't take any parameters. I'm not sure why there is one
Second, you setup your variable at runtime, meaning its value is static. If the ingame time at runtime was 2, then the time variable would remain 2 until the script is stopped.
Here is my fix to this:
local intakeAlert = game.StarterGui.Main.IntakeAlert
local prisonerCount = game.ReplicatedStorage.NumPrisoners
local intake = game.ReplicatedStorage.PrisonerIntake -- This is the prisoner intake status
local debounce -- Make sure this event doesn't fire several times
while true do
local currentTime = math.floor(game.Lighting.ClockTime) -- You can change this to GetMinutesBeforeMidnight if you want. Might have to do some math.
if currentTime == 8 then -- Checks if it is 8 hours after midnight.
if debounce then return end -- Return if the event has already been fired.
debounce = true
print("Prison Bus Arriving.")
intakeAlert.Visible = true
wait(2)
intakeAlert.Visible = false
else
debounce = false -- If its 9 after midnight, debounce will be set to false for the next day.
end
wait() -- You should avoid using this, I suggest changing it to something like RunService.Heartbeat:Wait() but that's your choice.
end
In order to gurantee Bounded wait in Test and set Instruction,following is the code given in Operating system book,Galvin -:
do {
1 waiting[i] = true;
2 while (waiting[i] && test_and_set(&lock)) ;
3 waiting[i] = false;
/* critical section */
4 j = (i + 1) % n;
5 while ((j != i) && !waiting[j])
6 j = (j + 1) % n;
7 if (j == i)
8 lock = false;
9 else
10 waiting[j] = false;
/* remainder section */
} while (true);
I am getting the complete code and concluded that
A process P_i will be in the critical section if either
Waiting [i]=false or test_and_set(&lock)=FALSE which ensures that Lock was FALSE previously. so Exit Section is either setting Waiting[j] or lock to FALSE.
But i have got some doubts-:
if in the exit section section it is found that same process again requests for critical section i.e
if j==i
then according to the code,that process have to start its execution form line number 2,i.e will execute
test_and_set(&lock))
in while loop and find the return value of test_and_set(&lock)) as false and then move to critical section.My doubt is that if same process wants to be in critical section ,is it necessary to start its exection right from line number 2
2.Now i want to do following Permutation and want to check the possible outcome.i want to swap line number 8 and 10
in line number 8 if i make
waiting[j]=false;
then also it will move to critical section even though lock =true now.
in line number 10 if i make
lock=false
then also it(process p_j) will move to critical section even though waiting[i]=true and i think it would be better because line number 3 will assign waiting[i]=false ,after the while loop breaks due to test_and_set(&lock)=false.
On the other hand if i make this change process have to execute test_and_set(&lock) which is time consuming
Is my assumption for point2 right?
what is the correct reason for point 1?
Thanks
Regarding point 1:
My doubt is that if same process wants to be in critical section ,is
it necessary to start its exection right from line number 2
A process is basically an program in execution. A process just cannot jump around choosing which instruction to execute next. The control flow decides that. The control of the code(which is the process itself) suggests that if a process successfully enters critical section, and again wants to enter critical section, then it will first execute lines 4 to 10 and then execute remainder section and would have to start execution right from line 1
Regarding your point 2
Now i want to do following Permutation and want to check the possible
outcome.i want to swap line number 8 and 10
If you swap the lines, the bounded waiting condition would no longer exist.
Proof
Suppose that only 1 process P(i) made the request to access Critical Section and it successfully entered. So
lock = true and waiting[i] = true
because only then it would have been able to come out of the for loop. Now it starts executing from line 4
Then j takes following values:
i + 2 , i + 3, ......0 , 1 , 2 , 3 , 4....i
wrap around of values occurs because of % operator. And Because no other process made request to enter critical section, waiting[j] = false for j != i
Therefore the condition while ((j != i) && !waiting[j]) becomes false when j equals i, and now we are at line 7. The new code is:
if (j == i)
waiting[j] = false;
else
lock = false;
Now if any process makes a request to enter critical section, then while (waiting[i] && test_and_set(&lock)) ; would always evaluate to true because lock is true and waiting[i] is also true and it would be stuck in spinlock. There would be no progress.
First off, for full disclosure I'm a n00b in RX, but I'm learning daily now...
I need to build an Observable that's going to enable a button (or automatically start an action) as long as a stream of another incoming observable averaged signals is coming in within a certain range. As far as I've learned so far, I could do that by adding a .Where to an averaged Observable in which I can then check that my observed average values created from an event handler are in fact within a given range...
What I need also however is to have these observable values influence the state of my action/button (allow it to be executed) just until its underlying/inner signals overstep the given range. Is such a thing in RX possible as a reversed .TakeUntil(inverse where clause) which I now think could maybe solve my problem, or should I just reuse the original observable and copy it with a negated .Where clause and then use that as another independent observable...if latter, is there some performance loss by reusing almost identical observables multiple times, just changing few their linq queries...how many observables is too much please?
It seems to me that something like this is sufficient.
var source = Observable.Range(0, 10);
var query =
source
.Buffer(4, 1)
.Select(xs => xs.Average())
.Select(x => x > 5.0 && x <= 7.0);
query.ObservableOn(button).Subscribe(enabled => button.Enabled = enabled);
(I've assumed Windows forms.)
This gives me:
False
False
False
False
True
True
False
False
False
False
I can improve it slightly like this:
var query =
source
.Buffer(4, 1)
.Select(xs => xs.Average())
.Select(x => x > 5.0 && x <= 7.0)
.StartWith(true)
.DistinctUntilChanged();
That then gives me:
True
False
True
False
Please let me know if I've missed anything.