Reputation: 67
For a course I'm following, I have to design some sort of AI that can navigate through a given 'terrain' which contains enemies (give damage), friends (lower the damage), obstacles (decrease energy) and stations (increase energy).
Before I proceed to the actual AI part, I want to have to the underlying point system in order. My question is; Is it possible to show 2 numbers at 1 turtle? I want to show damage as well as energy by the robot.
The energy part looks like the following:
to hit-station
ask robots
[ if pcolor = green
[ set pcolor black set energy (energy + energy-from-station) ]
ifelse show-energy?
[ set label energy ]
[ set label "" ]
]
end
Now this works perfectly fine since I made a switch for showing the energy. The problem arises when i want to add a number for the damage. I made a switch for this as well and the code part looks like the following:
to hit-obstacle
ask robots
[ if pcolor = red
[ set pcolor black set energy (energy + energy-from-obstacles) ]
ifelse show-damage?
[ set label damage ]
[ set label "" ]
]
end
I don't receive an error but the damage doesn't seem to show (the damage code part is beneath the energy code part). Is this possible and is there a way to assign a different color to the numbers?
Thanks a lot in advance,
J.V.
Upvotes: 0
Views: 358
Reputation: 9620
Using turtles-own
, you can assign as many attributes to a turtle as you wish. But a turtle can only have one value for its label. You must decide what is to happen if you have a turtle that finds both a station and an obstacle. You can show the energy, or show the damage, or show a label incorporating both. In terms of your code above, note that you never set damage
(only energy
), so you are probably just seeing a 0
label when damage
is reported.
Upvotes: 1