Author |
Message |
whitty
Joined: Sat Jun 16, 2007 2:31 am Posts: 2982 Location: Texas
|
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
|
Sat Jan 09, 2010 1:24 am |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
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
|
Sat Jan 09, 2010 2:25 am |
|
|
whitty
Joined: Sat Jun 16, 2007 2:31 am Posts: 2982 Location: Texas
|
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.
|
Sat Jan 09, 2010 3:51 am |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
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
|
Sat Jan 09, 2010 4:02 am |
|
|
Kyred
Joined: Sun May 31, 2009 1:04 am Posts: 308
|
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. loadstring() for the win. http://pastebin.com/m2883f5fcSo...umm....care to explain what self.target is supposed to be?
Last edited by Kyred on Sat Jan 09, 2010 4:39 am, edited 1 time in total.
|
Sat Jan 09, 2010 4:08 am |
|
|
whitty
Joined: Sat Jun 16, 2007 2:31 am Posts: 2982 Location: Texas
|
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.
|
Sat Jan 09, 2010 4:37 am |
|
|
Kyred
Joined: Sun May 31, 2009 1:04 am Posts: 308
|
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.
|
Sat Jan 09, 2010 4:39 am |
|
|
whitty
Joined: Sat Jun 16, 2007 2:31 am Posts: 2982 Location: Texas
|
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.
|
Sat Jan 09, 2010 4:41 am |
|
|
Kyred
Joined: Sun May 31, 2009 1:04 am Posts: 308
|
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
|
Sat Jan 09, 2010 4:42 am |
|
|
whitty
Joined: Sat Jun 16, 2007 2:31 am Posts: 2982 Location: Texas
|
Re: Inventory copying/pasting
You're a lifesaver, unlike some. Thanks man.
|
Sat Jan 09, 2010 4:51 am |
|
|
Kyred
Joined: Sun May 31, 2009 1:04 am Posts: 308
|
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
|
Sat Jan 09, 2010 5:03 am |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
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
|
Sat Jan 09, 2010 5:10 am |
|
|
whitty
Joined: Sat Jun 16, 2007 2:31 am Posts: 2982 Location: Texas
|
Re: Inventory copying/pasting
Changed it up to this: http://pastebin.com/m75d15c32And getting an error on line 16: ")" expected near 'gun'
|
Sat Jan 09, 2010 5:12 am |
|
|
Kyred
Joined: Sun May 31, 2009 1:04 am Posts: 308
|
Re: Inventory copying/pasting
Just caught some errors of mine. Quick fix: http://pastebin.com/m4dc1a494
|
Sat Jan 09, 2010 5:16 am |
|
|
whitty
Joined: Sat Jun 16, 2007 2:31 am Posts: 2982 Location: Texas
|
Re: Inventory copying/pasting
Still the ")" expected near 'gun' error on line 16. http://pastebin.com/m7f33bd7fAnd 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.
|
Sat Jan 09, 2010 6:05 am |
|
|
|