Data Realms Fan Forums
http://45.55.195.193/

Inventory copying/pasting
http://45.55.195.193/viewtopic.php?f=73&t=17536
Page 1 of 1

Author:  whitty [ Sat Jan 09, 2010 1:24 am ]
Post subject:  Inventory copying/pasting

I made & butchered a script that, when pressing a certain button, is written to:
1. Create a certain actor, but not spawn it in the game
2. Copy the weapon being held by the controlled actor and give it to the unspawned actor
3. Delete the controlled actor and switch control to the new actor (which is created at the original actor's exact location)
4. Play a little sound and have the new actor FlashWhite() for a brief time.

The script has no initial errors in the console, but when I press the activation button I get the error:
Code:
"WWM.rte/******/************.lua:16: attempt to index global 'target' (a nil value)"


Here is the script, I appreciate any help I get with this.
http://pastebin.com/f1fd173be

Author:  Grif [ Sat Jan 09, 2010 2:25 am ]
Post subject:  Re: Inventory copying/pasting

you explicitly have "target" defined as nil

what the ♥♥♥♥ did you expect to happen

you need to actually set the variable to a value in order to use it

gasp, lua does not read minds

EDIT: holy god this code is
literally
lafe-level

you arbitrarily set variables to local or global, randomly decide to omit the self prefix from semi-locals, have the object set to delete in your keypress statement such that the thing's going to remove itself before it finishes the code and oh my god this is comical

Author:  whitty [ Sat Jan 09, 2010 3:51 am ]
Post subject:  Re: Inventory copying/pasting

90% of that code isn't by me, so, suck it.
Also, the object deleting itself where it does works perfectly and is intended.

Author:  Grif [ Sat Jan 09, 2010 4:02 am ]
Post subject:  Re: Inventory copying/pasting

then you are absolutely terrible at copying code

your variable naming is all kinds of ♥♥♥♥ up and inconsistent as all hell

you also haven't even acknowledged that I found your problem in the first ten seconds of looking at your code

how exactly do you expect lua to know what self.target is
bonus: how exactly do you expect lua to know what just plain target is, when you haven't defined either of them

Author:  Kyred [ Sat Jan 09, 2010 4:08 am ]
Post subject:  Re: Inventory copying/pasting

OH GOD! All the unnecessary for loops! I can just hear CC screaming...excuse me while I clean this mess up...

EDIT:
Now that's how it's done. Quick and clean. 8) loadstring() for the win.
http://pastebin.com/m2883f5fc

So...umm....care to explain what self.target is supposed to be?

Author:  whitty [ Sat Jan 09, 2010 4:37 am ]
Post subject:  Re: Inventory copying/pasting

Kyred wrote:
So...umm....care to explain what self.target is supposed to be?

Dunno, I saw it in the original code and copied that out of it.


Thanks Kyred.

Author:  Kyred [ Sat Jan 09, 2010 4:39 am ]
Post subject:  Re: Inventory copying/pasting

the code won't work btw. It won't compile because I left self.target in there.

So does this script run on an actor? If so, I can fix this script up really quick for ya.

Author:  whitty [ Sat Jan 09, 2010 4:41 am ]
Post subject:  Re: Inventory copying/pasting

Yes, it does. It's run on two of them, so that when one actor runs it, it turns into the other.

Author:  Kyred [ Sat Jan 09, 2010 4:42 am ]
Post subject:  Re: Inventory copying/pasting

whitty wrote:
Yes, it does. It's run on two of them, so that when one actor runs it, it turns into the other.
Gotcha. Will take me a few minutes to fix.

Edit: And by few I mean several...gotta test some stuff

Author:  whitty [ Sat Jan 09, 2010 4:51 am ]
Post subject:  Re: Inventory copying/pasting

You're a lifesaver, unlike some.
Thanks man.

Author:  Kyred [ Sat Jan 09, 2010 5:03 am ]
Post subject:  Re: Inventory copying/pasting

This should work. I don't have the files to actually test it though. But it looks alright.

http://pastebin.com/m56d5b8f3

Author:  Grif [ Sat Jan 09, 2010 5:10 am ]
Post subject:  Re: Inventory copying/pasting

whitty wrote:
You're a lifesaver, unlike some.
Thanks man.


Quote:
I appreciate any help I get with this.


very appreciative yeah

I told you what was wrong is it my fault you don't know enough to fix it

Author:  whitty [ Sat Jan 09, 2010 5:12 am ]
Post subject:  Re: Inventory copying/pasting

Changed it up to this:
http://pastebin.com/m75d15c32
And getting an error on line 16: ")" expected near 'gun'

Author:  Kyred [ Sat Jan 09, 2010 5:16 am ]
Post subject:  Re: Inventory copying/pasting

Just caught some errors of mine. Quick fix:

http://pastebin.com/m4dc1a494

Author:  whitty [ Sat Jan 09, 2010 6:05 am ]
Post subject:  Re: Inventory copying/pasting

Still the ")" expected near 'gun' error on line 16.
http://pastebin.com/m7f33bd7f

And if it's all possible, could you make the edits to what I have here instead of your version? It's a hassle to keep changing it back and forth every time.

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/