Scripts / Slightly modified Vanilla-Scripts not working (Entity-pickup)

Author
Message
bluegekko
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location: Flensburg - Schleswig-Holstein - Germany
Posted: 4th Feb 2017 16:14
Hey guys,

I've been using GameGuru for some days now mainly experimenting with level design and such, which worked just like a charm.
Buuut just as I wanted to start adding some entities for the player to interact with, things went downhill.
So, here's the scenario:
The player should be able to decide if he wants to pick up an item or just leave it (for later use).
For example a medikit or a healing plant or something like this.
So my thought was:"Okay, simple enough! Just take the "health.lua"-script and check online for how to prompt for the pickup option!"
In the end, this is what I came up with:
(for this I copied the "health.lua" and renamed the copy "health_plant.lua". And yes, in the entity-properties this script is used)


As you can see, it's just the vanilla script with the "press e to pick up" line added.
But for some reason nothing is shown now when approaching the item.

The case gets weirder: (at least for me as the lua-newbie I am)
Tried some modifications with the "weapon.lua" and the "ammo.lua" as well.
Here are the codes:
(weapon_pickup.lua ; I just modified the prompted texts to make them a bit shorter and also changed the "if playerguncount < X"-value from 9 to 2 hoping this would be used as the overall maximum of weapons the player can carry)


(ammo_pickup.lua ; here I added the line "ammo_name[e] = name" in hopes that this would store and later display the name of the entity. also added the "press e to pickup" line so the player can choose to leave it.)


So, in short:
there are three scripts which were copied, renamed and modified with some (simple?) lines of code.
They are all set in the corresponding entity-properties.
when testing the game and approaching the entities, nothing gets displayed, the "e"-key is not responding as well. It's just as there is no script assigned to them.
The scripts are saved in the same folder as the original ones.

Oh boy, what a long first entry here.
And I have the feeling this won't be the last

Really hope someone can help me out with this, especially since I think I just made a very stupid or simple error there. Would love to know what went wrong *g*

Anyway, wish you all a nice day or evening, depending on where you live of course
/bg
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 4th Feb 2017 17:08
The name of the functions in the script must match the filename so in the first example it should be "function health_plant_main(e)".
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 4th Feb 2017 18:13
Look at the very first line of all 3 scripts, it's telling you the reason
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
bluegekko
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location: Flensburg - Schleswig-Holstein - Germany
Posted: 4th Feb 2017 18:56
Uhm...
Thank you two!
By changing this it actually worked!
However now the "Healing plant" is slowly killing instead of healing the player, wonder what that's about again.
Oh, and there seems to an issue with the ammo_name value defined in the ammo_pickup.lua as it keeps producing an error during testplay (something with a nil value, which should be an empty or unused one if I'm not mistaken).
Ha, no learning without a little challenge!
I'll try to solve these issues now, but I'll be back with another beginner-question sooner or later
Thank you both again, have a nice day!
/bg
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 4th Feb 2017 20:33 Edited at: 4th Feb 2017 20:35
If a script attempts to use an undefined variable in a mathematical action it will stop with the error "expected number".

Basically in Lua you only have 4 'types' that a variable can have, number, string, boolean or list.

All numbers are full 64 bit floats, strings are weird in that they are not actually ascii strings as such so unless doing something simple you should always use the string library to manipulate them safely.

Booleans are really simple, false or true (or nil, lol). Actually when testing a nil is treated as false.

Lua will convert between types based on usage so "123" + 4 will give you 127 whereas 123 .. "4" will give you "1234".

Lists are absolutely awesome, I highly recommend buying the Lua reference manual to learn about them properly.

'nil' in any variable means it hasn't been given a value yet .
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 4th Feb 2017 23:55 Edited at: 5th Feb 2017 00:09
To return the name from the properties to lua you need to slightly alter the init(e) of a script to look like this

(The name still needs to match etc, just a little bit extra, same as with the weapon script you posted above).
P.s. in your code you used
Quote: "ammo_name[e] = name"
, if an array doesn't exist you will need to create it first with
Quote: "ammo_name = {}"

(weapon_name = {} is already defined elsewhere in the lua system as it's used by the stock scripts so that's why you don't see it in the weapon script).

For healing this is because the old/default method to add health uses the hard coded value in the fpe file of the entity (quantity), if its a negative value then the player will take damage.
There's a post on this very recently where I gave a better script solution (on phone right now so I'll let you search it)
Here you go
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
bluegekko
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location: Flensburg - Schleswig-Holstein - Germany
Posted: 5th Feb 2017 10:00
Yay, this is awesome!
I probably lost quite an amount of precious lifetime yesterday experimenting with the scripts and crosschecking with vanilla-lua's why it didn't work, but that's fine (and provided more scripting insides!).
Checked this thread again today and WAM! - learned some new things thanks to you two again! The ammo pickup as well as the health-plant are working as planned now, thanks a lot!
Back to experimenting now

Have a nice day everyone!
/bg
*enter funny/sad/thoughtprovoking/historical/punny/antique signature line here*
PM

Login to post a reply

Server time is: 2024-03-28 11:40:53
Your offset time is: 2024-03-28 11:40:53