Jump to content

Unexpected error?


Recommended Posts

I have found a, hopefully, working function for sleeping, and it is almost done, finally. It is only this part that is failing. Everything else is working perfectly. The error reads as the following. ":90: Unexpected symbol near '>' " I have underlined the line with the error, and boldified <(Yes I did just do that) where the problem lies, but I am lost from here. The code works fine when this is not here. The numbers are there just to say what line it is.

[89]    inst:ListenForEvent("sanitydelta", function(inst, data)
[90]        if inst.components.sanity.current < 10 and > 20 then
[91]            v:PushEvent("yawn", {grogginess = 20})
[92]        end
[93]        else if inst.components.sanity.current < 10 then
[94]            v:PushEvent("yawn", {grogginess = 60, knockoutduration = 120})
[95]        end
[96]    end)

Surrounding code \/image.thumb.png.17b578d66f96fcb92bc26da95f8b794f.png

Update:

Found something that maybe worked a bit better?

inst:ListenForEvent("sanitydelta", function(inst, data)
        if inst.components.sanity.current < 10 and > 20 then
            v:PushEvent("yawn", {grogginess = 20})
        else if inst.components.sanity.current < 10 then
            v:PushEvent("yawn", {grogginess = 60, knockoutduration = 120})
        end
    end
end)

Edited by Kevin_Glitch
Possible found something.
Link to comment
Share on other sites

It's because you're using a compare operator without an operand.

inst:ListenForEvent(
    "sanitydelta",
    function(inst, data)
        local cursanity = inst.components.sanity.current
        if cursanity < 10
        then
            v:PushEvent("yawn", {grogginess = 60, knockoutduration = 120})
        elseif cursanity < 20
        then
            v:PushEvent("yawn", {grogginess = 20})
        end
    end
)

This will make it such that if the sanity is on the range of [0,10) that they get knocked out, and with [10,20) they get groggy.

You may need to compare an old sanity value to make it fire on edge trigger rather than continuously sending the event "yawn", but that's on you.

Link to comment
Share on other sites

13 hours ago, Kevin_Glitch said:

Can you explain an edge trigger and how to do it? I am a basic at all of this.

You store the old value and compare to it with the new value, then apply your changes if the 'edge' changes, either on rising or falling.

-- Game provided
a = {}
a.current = 15


-- Post init
a.old = a.current


-- Event callback
if a.current < threshold1
then
  if not (a.old < threshold1)
  then
    print("falling edge threshold1")
  end
elseif a.current < threshold2
then
  if a.old < threshold1
  then
    print("rising edge threshold1")
  end
  if not (a.old < threshold2)
  then
    print("falling edge threshold2")
  end
elseif a.old < threshold2
then
  print("rising edge threshold2")
end
a.old = a.current

 

Link to comment
Share on other sites

i think this would work good

inst:ListenForEvent("sanitydelta",function(inst, data)
	if inst.components.sanity.current < 10 then
		if inst.yawn_cd == nil then inst:PushEvent("yawn", {grogginess = 60, knockoutduration = 120}) end
		inst.yawn_cd = true
		inst:DoTaskInTime(10, function() inst.yawn_cd = nil end) --(can replace 10 with cooldown time of when this happens)
	elseif inst.components.sanity.current < 20 then
		if inst.yawn_cd == nil then inst:PushEvent("yawn", {grogginess = 20}) end
		inst.yawn_cd = true
		inst:DoTaskInTime(10, function() inst.yawn_cd = nil end) --(can replace 10 with cooldown time of when this happens)
	end
end)

 

Edited by Warbucks
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...