简体   繁体   English

资源池中的空闲单元

[英]Idle units in resource pool

I have a resource pool with only 1 resource unit, I'd like to have a node "myArea" changes its color depending on if the resource unit is idle or busy.我有一个只有 1 个资源单元的资源池,我想让节点“myArea”根据资源单元是空闲还是忙碌来改变它的颜色。 I typed the following code in a function "updateColor" body which I call in the resource pool actions "on seize" and "on release" (and in the Main agent "on startup").我在函数“updateColor”主体中键入了以下代码,我在资源池操作“on seize”和“on release”(以及主代理“on startup”)中调用该代码。

int idleUnits = speedyBag.idle();
if (idleUnits == 1){
myArea.setFillColor(Color.GREEN);
} else if (idleUnits == 0) {
myArea.setFillColor(Color.RED);
}

However this code doesn't work as I expected, the simulation starts with a green area but when the resource unit is seized it turns red and stays red forever.然而,这段代码并没有像我预期的那样工作,模拟从一个绿色区域开始,但是当资源单元被占用时,它会变成红色并永远保持红色。 I guess with我猜

speedyBag.idle()

I'm not pointing at what i think (the number of idle units in the pool, indicated in the picture).我不是指我的想法(池中空闲单元的数量,如图所示)。 Any suggestions?有什么建议?

image图片

No need for your approach, you can just use the dynamic color property of your node.不需要你的方法,你可以只使用节点的动态颜色属性。 Code below ensures the node fills green if you have 1 or more idle units.如果您有 1 个或多个空闲单元,以下代码可确保节点填充绿色。 If all are busy, it shows red:如果都忙,则显示红色: 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM