Scripts / Entity names

Author
Message
MChapman
8
Years of Service
User Offline
Joined: 19th May 2015
Location: USA
Posted: 10th Aug 2016 01:50 Edited at: 10th Aug 2016 03:08
Is there an easier way of obtaining the entity names then what Lee showed us in broadcast #50? The way he shows I'll have to use scriptname_init_name in all of my scripts. Here is what I'm wanting to do. In my npc talking script i want to store all the Random chatter in one table like so



The key of the table will be the name of the entity, I want to use the same function in every npc script that will get the name of the entity and match it up with the g_npc_dialog table key, so "conversation one.", will be the first entities prompt. The point of this is so I dont have to make a billion scripts for conversations, I can just store all the conversations in one script with an id use them that way sort of like a database? I hope i explained enough . If his way is the easiest or the only way of doing it thats fine I figured i would check just to see.
Markchapman10 is my Skype let's have some dev talk.
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 10th Aug 2016 09:34
Yep, that's correct.
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Nathan38
13
Years of Service
User Offline
Joined: 13th Feb 2011
Location:
Posted: 10th Aug 2016 17:33
I'm interested in learning about Arrays too actually, currently I'm making an inventory system.

Is it possible to create a list of ingredients with a quantity for each in an array, and then display all of that data? or would that be two separate arrays?

I've never used them before in LUA so I'm a bit confused
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 10th Aug 2016 17:57
You can use both.
Arrays : https://www.lua.org/pil/11.1.html

or Multi-Dimensional Arrays: https://www.lua.org/pil/11.2.html

Anyway here you've some clue.

ingredients = {sugar=1,piper=3,eggs=4}

3com
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics

PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 10th Aug 2016 20:11 Edited at: 10th Aug 2016 20:15
Lua doesn't actually have arrays, it has one structure called the list.

Here is an example form one of my scripts:


You can mimic the behaviour of arrays using lists by simply making the key values numeric of course which seems to be the way most people use them.

Lists can contain other lists and indeed functions so you can encapsulate the data and the functions to work on the data within a single list, great for OOP.

Been there, done that, got all the T-Shirts!
PM
MChapman
8
Years of Service
User Offline
Joined: 19th May 2015
Location: USA
Posted: 11th Aug 2016 03:02 Edited at: 11th Aug 2016 04:32
How you structured your table helps alot, I've been watching basic lua videos and A basic version of the script done. Thanks for the help guys! If you want to see the script you can check it out in my systems post.


edit: I'm having some difficulties. I can get this to work, but for some reason the text wont come up, the prompt works but the text wont display....


any ideas?
Markchapman10 is my Skype let's have some dev talk.
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 11th Aug 2016 13:37
what are the values of
npc_namex ,npc_namey and text_size?
x and y should both be within 100 and text_size should be 1 ~ 5
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Nathan38
13
Years of Service
User Offline
Joined: 13th Feb 2011
Location:
Posted: 11th Aug 2016 14:49 Edited at: 11th Aug 2016 15:33
Thanks for the info all!

@AmenMoses
If I were to adapt your example, is this how I would set it up?



and if I then wanted to add or remove items from the quantity I would say something like:


Also is it possible to display a list as text? Or even better display only items as text where quantity is greater than 0?
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 11th Aug 2016 19:48
It would be :


Which looks quit unwieldy until you learn that "=" in Lua really does mean it, for example:



'eggs' in this example is not a new variable but is effectively a pointer to the item in the list g_player_ingredients with the key 'ingredient1'

Of course as we're all supposed to be OOPs black belts these days what you should be doing is creating functions within your 'objects' (methods iow) to handle things like incrementing values within them. So for example you would have a call like g_player_ingredients.add ('eggs', 1).

I can recommend THE book on Lua, 'Programming in Lua' by Roberto Ierusalimschy (the chap that created Lua). It is an extremely powerful language when used properly.

As an example if you wanted to loop through all the active entities in GG you could do worse than:



Been there, done that, got all the T-Shirts!
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 11th Aug 2016 20:34
A more complex example, this is a snippet from my scrolling map script:


It's part of the code that displays enemies and objective on the scrolling map display.
Been there, done that, got all the T-Shirts!
PM
Nathan38
13
Years of Service
User Offline
Joined: 13th Feb 2011
Location:
Posted: 11th Aug 2016 22:05 Edited at: 11th Aug 2016 22:09
Thanks for the explanation mate, honestly this stuff has been confusing!

I was getting caught up on the for loops, (like for, k,v,i do) that bit was really confusing but this video has helped me so much with that:

https://www.youtube.com/watch?v=fKJk8-8YSwA

Does the print command work in GG? Like can I use the print to get some data from the table using the for k,v pairs thing then use the Text command to display that?
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 11th Aug 2016 22:30
I haven't played with the text commands yet so can't help much with that but I assume you can just use the GG text commands within loops etc.

One thing to be aware of is that pairs does not iterate the list in order but ipairs does, but ipairs stops when it hits a nil entry.

What this means is that if you have a list with keys 1,2,3,4, nil, 6, 7, then ipairs will iterate 1, 2, 3, 4 then stop, pairs might go 2, 4, 3, nil, 7, 6, 1 (basically the order is usually the order that the entries were added to the list) so within a pairs iterator you should check the keys for nil entries.

(when you try to do something like maths on a nil entry Lua will throw an error which in GG will cause it to crash out)

Been there, done that, got all the T-Shirts!
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 11th Aug 2016 22:40
Btw the sort_pairs function in my earlier snippet is open source , there are plenty of web sites out there with similar useful functions that are also open source (i.e. free to use) so go explore. (which ones will work with GG otoh is something you'll just have to discover the hard way)
Been there, done that, got all the T-Shirts!
PM
MChapman
8
Years of Service
User Offline
Joined: 19th May 2015
Location: USA
Posted: 12th Aug 2016 04:33 Edited at: 12th Aug 2016 04:37
The values are 50 so it draws the text where i can see it, but I figured it out and its now on display on my systems thread. I think the text size may have been messing up cause I had it at 20.
Markchapman10 is my Skype let's have some dev talk.
Belidos
3D Media Maker
8
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 12th Aug 2016 08:04 Edited at: 12th Aug 2016 08:04
Quote: " I think the text size may have been messing up cause I had it at 20."


As far as i'm aware text sizes are 1 to 5, just like in html

i5, NV960 2GB, 16GB memory, 2x 2TB Hybrid, Win10.
i3 , Intel integrated graphics, 6GB memory, 512GB Generic SATAIII Win8.1.
Intel Celeron (duel Core), Radeon integrated graphics, 4GB memory, 180gB Generic SATAII, WinVista.
Q6600, Intel integrated graphics, 8GB memory, 512GB Generic SATAII, Win7.
MChapman
8
Years of Service
User Offline
Joined: 19th May 2015
Location: USA
Posted: 12th Aug 2016 12:46
Thats what it was then it had to be.
Markchapman10 is my Skype let's have some dev talk.

Login to post a reply

Server time is: 2024-05-04 04:41:19
Your offset time is: 2024-05-04 04:41:19