Jump to content

help with function arguements


Recommended Posts

	inst:ListenForEvent("healthdelta",
    function(inst, data , follower)
        local bal = inst.components.leader:numfollower
		local pos = bal:GetPosition()
		if bal > 0 then 
		inst.Physics:Teleport(pos)
        end
    end
)

i need help as when i try to use this code it says  function arguments expected near 'local' which i have no idea how to fix if you have any idea on how to fixe this that would be awsome, if i manage to accomplish it myself i'll change the title to solved

Link to comment
Share on other sites

local bal = inst.components.leader:numfollower

this line is the reason. Whenever you use ":" it means you are calling a function. And if so, you have to had the brackets to call a function. So now find out if numfoller is a function, then add brackets. Or if it is not a fucntion, then change the : into a .

But even then your code wont work. numfolloer is most likely a number. And I doubt you can do GetPosition() on a number.

Link to comment
Share on other sites

33 minutes ago, thomas4845 said:

ok yeah thnx tho i'll try to find a way

a hint how to deal with events:
Search the gamecode (eg the notepad++ search all files) to see where and how this event is pushed, so search for PushEvent("healthdelta" , most probably within the health component.  There you can see what information is sent within this event.  The first argument is always the inst that is pushing this event, and the second is always "data", usually there is no third (so no "follower" within your code.)
The data is usually a table , in yor case it looks like this: { oldpercent = old_percent, newpercent = self:GetPercent(), overtime = overtime, cause = cause, afflicter = afflicter, amount = amount }
This means you can eg. access the amount with "data.amount", in case you need this value. Also you can access the "afflicter" this way.
To get more information about the leader component, open the file and see what functions you find. Eg there you also see code how to loop through all followers, if you want it. Or if your inst is a follower, than look at the follower component.

Edited by Serpens
Link to comment
Share on other sites

local function dodge (inst, data , pos)
 
        local x,y,z = inst.Transform:GetWorldPosition()
        local bal = FindEntity(x,y,z, TUNING.ONEMANBAND_RANGE, {"balloon"}, nil)
		if bal > 0 then
		local pos = bal.Transform:GetWorldPosition()
		inst.Physics.Teleport(pos)
end
end

this is gonna make me cry i don't know what's the problem , i don't know why it says it's trying to index local inst as number value

Spoiler

[00:01:15]: [string "scripts/simutil.lua"]:32: attempt to index local 'inst' (a number value)
LUA ERROR stack traceback:
    scripts/simutil.lua:32 in (global) FindEntity (Lua) <31-42>
    ../mods/00 maxwel rework/scripts/prefabs/wes.lua:26 in (local) fn (Lua) <23-31>
    scripts/entityscript.lua:1040 in (method) PushEvent (Lua) <1027-1054>
    scripts/components/health.lua:377 in (method) DoDelta (Lua) <364-383>
    scripts/components/health.lua:111 in (method) ForceUpdateHUD (Lua) <110-112>
    scripts/components/health.lua:133 in (method) OnLoad (Lua) <122-141>
    scripts/entityscript.lua:1585 in (method) SetPersistData (Lua) <1576-1593>
    scripts/mainfunctions.lua:1455 in () ? (Lua) <1451-1463>
    =[C]:-1 in (method) SendResumeRequestToServer (C) <-1--1>
    scripts/prefabs/world_network.lua:30 in (field) fn (Lua) <19-34>
    scripts/scheduler.lua:177 in (method) OnTick (Lua) <155-207>
    scripts/scheduler.lua:371 in (global) RunScheduler (Lua) <369-377>
    scripts/update.lua:180 in () ? (Lua) <159-238>

 

Link to comment
Share on other sites

2 hours ago, thomas4845 said:

local function dodge (inst, data , pos)
 
        local x,y,z = inst.Transform:GetWorldPosition()
        local bal = FindEntity(x,y,z, TUNING.ONEMANBAND_RANGE, {"balloon"}, nil)
		if bal > 0 then
		local pos = bal.Transform:GetWorldPosition()
		inst.Physics.Teleport(pos)
end
end

this is gonna make me cry i don't know what's the problem , i don't know why it says it's trying to index local inst as number value

  Reveal hidden contents

[00:01:15]: [string "scripts/simutil.lua"]:32: attempt to index local 'inst' (a number value)
LUA ERROR stack traceback:
    scripts/simutil.lua:32 in (global) FindEntity (Lua) <31-42>
    ../mods/00 maxwel rework/scripts/prefabs/wes.lua:26 in (local) fn (Lua) <23-31>
    scripts/entityscript.lua:1040 in (method) PushEvent (Lua) <1027-1054>
    scripts/components/health.lua:377 in (method) DoDelta (Lua) <364-383>
    scripts/components/health.lua:111 in (method) ForceUpdateHUD (Lua) <110-112>
    scripts/components/health.lua:133 in (method) OnLoad (Lua) <122-141>
    scripts/entityscript.lua:1585 in (method) SetPersistData (Lua) <1576-1593>
    scripts/mainfunctions.lua:1455 in () ? (Lua) <1451-1463>
    =[C]:-1 in (method) SendResumeRequestToServer (C) <-1--1>
    scripts/prefabs/world_network.lua:30 in (field) fn (Lua) <19-34>
    scripts/scheduler.lua:177 in (method) OnTick (Lua) <155-207>
    scripts/scheduler.lua:371 in (global) RunScheduler (Lua) <369-377>
    scripts/update.lua:180 in () ? (Lua) <159-238>

 

translation:
you are trying to do number.xyz , so you have a "." after a variable that is a number (or number["xyz"])
Now you have to look at the line with the error message, in this case simutil.lua in line 32:

Quote

local x, y, z = inst.Transform:GetWorldPosition()

The only thing with a "." before is "inst", so obviously you are giving it a number instead of a inst. And in your code ou see, you give him x insead of an inst. problem solved.
function FindEntity(inst, radius, fn, musttags, canttags, mustoneoftags)

So take a look at what FindEntity is doing and if this is what you want. Maybe you want instead:
"TheSim:FindEntities(x, y, z, TUNING.BIRD_CANARY_LURE_DISTANCE, { "scarecrow" })" (example from birdspawner to find near scarecrows, this will return a list of found objects)

FindEntities will need x,y,z coordinates and will give you a list of every found item.
FindEntity wants an inst instead to search in his radius and will return the first found object.

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...