For example, in “Storming the Farmhouse”, what if I want my hero to shield for 5 seconds when I place a black flag? I am using LUA, but Python, JavaScript, or help in any coding language would be appreciated.
In order to avoid posting a solution as is on the forum, allow me to post a specific snippet of code. I am only including the necessary parts that I believe are necessary to “shield for 5 seconds”, if such a thing is even possible at this point. (If it requires more advanced coding knowledge, please share!)
while true do
local flag = self:findFlag()
local green = self:findFlag("green")
if green then
self:pickUpFlag(green)
self:shield(5)
end
end
As you can see, I attempted to pass 5 as the argument for the shield function (if I understand correctly, the shield function is predefined in the game.) In game, however, It seems like my hero only shields for 0.4 seconds (that’s how long the game says “shield” takes.)
while true do
local flag = self:findFlag()
local green = self:findFlag("green")
if green then
self:pickUpFlag(green)
self:shield()
self:say(wait)
self:say(wait)
self:say(wait)
self:say(wait)
self:say(wait)
end
end
You’re trying to create a hero behavior in a game where the hero shields for a specified amount of time when a flag is placed. However, the game’s built-in functions might not directly support specifying the duration of the shield. Instead, the shield function in the game might be a simple toggle to turn the hero’s shield on or off.
If the game’s shield function doesn’t support a duration parameter, you’ll need to implement your own logic to simulate the shield for a specific duration. Here’s a modified version of your code that simulates a 5-second shield:
local isShielded = false
local shieldStartTime = 0
local shieldDuration = 5 -- The desired shield duration in seconds
while true do
local flag = self:findFlag()
local green = self:findFlag("green")
if green then
self:pickUpFlag(green)
isShielded = true
shieldStartTime = self:now()
end
if isShielded then
local currentTime = self:now()
-- Check if the shield duration has elapsed
if currentTime - shieldStartTime >= shieldDuration then
isShielded = false
else
self:shield() -- Continue shielding
end
end
end
In this code, when the green flag is picked up, isShielded is set to true , and the shieldStartTime is recorded. Then, in the loop, it continuously checks if isShielded is true . If it is, it calculates the time that has passed since the shield was activated. If the shield has been active for 5 seconds, it sets isShielded to false . While isShielded is true , it keeps calling self:shield() to maintain the shield.