Jump to content

Nil values


CoolBeans
 Share

Recommended Posts

BluHornets Tutorial. Gone over them can't find the obvious.

He makes a helath box, ammo box and hurt box. The scripts below.

I either miss where he adds something to the FPSplayer script

or he forgets to mention it to avoid these errors?

 

 

 

********************************************************************

 

AMMOBOX-

attempt to index field 'weapons' (anil value) line 3

 

 

Script.AmmoAmount=50 --float

function Script:Use(player)

player.weapons[player.currentweaponindex].ammo =

player.weapons[player.currentweaponindex].ammo + self.AmmoAmount

self.entity:Release()

end

 

********************************************************************

HEALTHBOX-

atempt to call method 'ReceiveHealth' (a nil value) line 4

 

 

Script.HealthAmount=50 --float

 

function Script:Use(entity)

entity:ReceiveHealth(self.HealthAmount)

self.entity:Release()

end

 

 

********************************************************************

 

HURTBOX-

attempt to call 'Hurt' (a nill value) line 7

 

 

Script.HurtAmount=25 --float

 

function Script:Start()

end

 

function Script:Use(entity)

entity:Hurt(self.HurtAmount)

end

 

*************************************

 

 

 

 

 

 

 

 

 

 

This is Jorns health kit I got working but If I remember right something is added to FPSplayer for i

to work. Maybe that's the problem above. I tired to PM bluH about this he must be busy.

 

Thanks

CB

 

Script.health = 15.0 --float "Health"

Script.useOnce = true --bool "Use once"

 

function Script:Start()

if self.health < 0 then

error("Health can't be a negative value.")

end

end

 

function Script:Use(player)

if player.script.health < player.script.maxHealth then

player.script:ReceiveHealth(self.health)

if self.useOnce then

self.entity:Release()

end

end

end

Link to comment
Share on other sites

Same error. His script calls for "person.weapons" I even tried changing all instances to "player"

same error

 

Script.ammoamount=6 --int "Ammo Amount"

Script.ammotype=1 --int "Ammo Type"

 

function Script:Use(player)

for a=0,6 do

if player.weapons[a]~=nil then

if player.weapons[a].index==self.ammotype then

if player.weapons[a].ammo+player.weapons[a].clipammo<player.weapons[a].maxammo then

player.weapons[a].ammo= player.weapons[a].ammo + self.ammoamount

if player.weapons[a].ammo+player.weapons[a].clipammo>player.weapons[a].maxammo then

player.weapons[a].ammo=player.weapons[a].maxammo-player.weapons[a].clipammo

end

self.entity:Release()

self.entity=nil

return

end

end

end

end

end

 

If I could get it to work and define ammo type per gun that would be aces! I think something must be added

to FPSplayer.

Link to comment
Share on other sites

His calls person.weapons because person is what he called his function argument parameter.

 

I think the assumption here is that the fpsplayer.lua is calling this scripts Use() function and passing itself into it. I don't use the FPSPlayer.lua script but does it have a weapons table in it?

 

Now passing itself could be either that it passes 'self' or 'self.entity'. If it passes 'self' then it's the script itself and you can use script variables directly from the function parameter. If it's 'self.entity' then you'd have to use 'person.entity.script.variable' which would be silly that it does that. No real sense in passing self.entity to the Use function.

 

You have to know what is calling these Use() functions and what they are passing in as the parameter, in order to debug this stuff.

Link to comment
Share on other sites

Yes I assumed that "person" could be any name. Ie Player, Character, John, Moses. Whatever your "player" is named.

Since the FPSplayer script uses player it makes more sense to me to keep it that way.

 

I'm trying to understand what Rick said but I'm not far along enough to fully make it all click and work. Wont

stop me from trying however.

 

All I know is BlueH doesn't go over adding any code anywhere else. He makes a box. Give is a mass of 1

makes it a prop and give this code to the box.

 

 

 

********************************************************************

 

AMMOBOX-

attempt to index field 'weapons' (anil value) line 3

 

 

Script.AmmoAmount=50 --float

function Script:Use(player)

player.weapons[player.currentweaponindex].ammo =

player.weapons[player.currentweaponindex].ammo + self.AmmoAmount

self.entity:Release()

end

 

Then he uses the stock prefab FPSplayer in the scene and it works fine so you got me as to why it does not work.

Same with his small hurt script above and health script. The tutorials are 2 months old so its very frustrating they don't work.

 

Honestly I figured most of you experts could look at things like this and in 5 sec say

"hey here the problem" am I crazy to be thinking this? Specially dealing with stock or add-on assets...

 

Thanks again

CB

Link to comment
Share on other sites

I deleted my post above because it is giving me problems too....every time I think I have it figured out it gives me more problems...I will post again if I get it figured out...Rick is right about the 'person.entity.script.variable' being silly...it does work well with the Health though....sorry for any inconvenience....

 

No problem man your help big or small is greatly appreciated!

I'm glad someone is in the same boat with me I just hope it doesn't sink on us smile.png

 

CB

Link to comment
Share on other sites

Yes I assumed that "person" could be any name. Ie Player, Character, John, Moses. Whatever your "player" is named.

 

It can be named anything but it has nothing to do with whatever your player is named. Look at the Use function. It has a parameter called "person" (or "player"). That's what you are using inside the function. Something is calling this function and it's passing an object (most likely the player script) into it. When you are inside the function the variable name you use to access that object is whatever the parameter name is. That parameter could be named 'a' or 'i' for all we care. It's just a variable that allows you to access whatever was passed into that function when it was called.

 

Use() is not an LE special function. It's being called (most likely from FPSPlayer.lua). Find out where it's being called from and see what is being passed in.

 

Knowing about function parameters is fairly basic programming 101 stuff and has nothing to do specifically with LE. You might be better off in either taking a lesson from me or reading up on just Lua in general.

 

This error is telling you that the weapons variable doesn't exist in the player variable object.

Link to comment
Share on other sites

I'm hoping to take this topic further as I do want to make my zombies drop random ammo per gun.

I have random spawning zombies and random dropping guns and health packs working. I have the

hud working, day night cycle, zombie kill score all working. Once I get this going motivation will be

great and lean towards level design since Ill be satisfied with mechanics at that point for a while.

Oh quick question too why can't the FPSplayer crouch? I admit I have not looked the code over

for contrl key use. I will now and try to answer my own question lol. Too much coffee!!!

Link to comment
Share on other sites

Yes Rick its "player" the only part of this I'm fully understanding. Some lessons would be nice. I currently have no cash

but when I do I will consider your services for sure. I'm just a guy tired of his job trying to changed gears half way through

life while sitting at home with no work. Ive got 150 hours into this so no I don't know the most basic stuff. However I am trying

to keep my motivation going with what I have achieved so far. (Impressed myself anyways) I will study up more on functions.

I'm still in the if, then, and, early stages of comprehension so bare with me biggrin.png

Link to comment
Share on other sites

Ok so the FPSPlayer script passes "self" to the used object's script by base. You can verify this in yours by checking for

 

--Use the object, whatever it may be

usableentity.script:Use(self)

 

The self in the () is the key here. It should be in the basic FPSPlayer script. Also you must have a weapon on you before you can pick up ammo. I wrote the scripts very simply to focus on the core of how they worked so I did not add checks to see if you have a weapon yet.

 

The FPSPlayer script holds a weapons table. The table is populated from the FPSGun script when a weapon is given to the player. If the player does not have a gun yet then the table is nil and there cannot be a clipammo variable in it. That is more than likely the error from the ammo box.

 

If that does not work then let me know.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...