Practice Lua Scripts
Moderator: Moderators
Practice Lua Scripts
I have perused scripts trying to understand what they do and they are all very complex. Are there any scripts in particular that are easier to understand for beginners?
Re: Practice Lua Scripts
Code: Select all
function widget:GetInfo()
return {
name = "Name as shown in widget list",
desc = "",
author = "john doe",
date = "date",
license = "PD",
layer = 0,
experimental = false,
enabled = true
}
end
local stringOfWords = "BLAH BLAH BLAH"
local toggle
function widget:Initialize()
Spring.Echo(stringOfWords .. " I STARTED LOOK AT ME JIM!")
end
function widget:Update(frame)
if(toggle == true) then
Spring.Echo("TOCK")
toggle = false
else
Spring.Echo("TICK")
toggle = true
end
end
Re: Practice Lua Scripts
Yes, except that bif this were actually written for beginners in mind it would have more comments in the code, of what it does.
Re: Practice Lua Scripts
Not sure what "difficulty level" you are looking for, so just general answer:
1) Lua itself:
For learning Lua (loops, variables, functions,..) there are better places/tutorials in web than spring offers.
Imo NOT recommend to learn Lua (or even scripting) via spring, it will take longer than reading normal tutorials first.
2) Spring-Lua:
imo problematic to learn from examples because of one or several points:
...long & complicated
Too hard for beginner
...easy logic but deal with something very specific to spring engine
"What does this even try to solve?"
...would be 1/5 the size if not for all the "extra situations" that need to be handled
Tricky to see which parts are really important
...have mistakes that go unnoticed because for this script the mess-up is irrelevant.
But maybe not for you.
...require other files from game (like units, weapons, other scripts,...)
Can be annoying.
...written by someone who was/is beginner himself
Pick up bad habits
Neither is something you would want to learn from.
In general learnining any spring modding by example is not so good. There are some okay examples but just as many bad or outdates ones.
Similiar with forum or chat. In conclusion nothing/noone, including this post, can be trusted and you should remain skeptical against everything.
If you want an example, no need to look very far.
See wiki for correct..Ops. On wiki it says "none", but description is ok
1) Lua itself:
For learning Lua (loops, variables, functions,..) there are better places/tutorials in web than spring offers.
Imo NOT recommend to learn Lua (or even scripting) via spring, it will take longer than reading normal tutorials first.
2) Spring-Lua:
imo problematic to learn from examples because of one or several points:
...long & complicated

...easy logic but deal with something very specific to spring engine

...would be 1/5 the size if not for all the "extra situations" that need to be handled

...have mistakes that go unnoticed because for this script the mess-up is irrelevant.

...require other files from game (like units, weapons, other scripts,...)

...written by someone who was/is beginner himself

Neither is something you would want to learn from.
In general learnining any spring modding by example is not so good. There are some okay examples but just as many bad or outdates ones.
Similiar with forum or chat. In conclusion nothing/noone, including this post, can be trusted and you should remain skeptical against everything.
If you want an example, no need to look very far.
The parameter of Update() is not frame.function widget:Update(frame)
See wiki for correct..Ops. On wiki it says "none", but description is ok
Re: Practice Lua Scripts
His next step would be to learn to use the wiki. You are welcome to post a better example documented and all.Jools wrote:Yes, except that bif this were actually written for beginners in mind it would have more comments in the code, of what it does.
Same as above...8611 wrote: If you want an example, no need to look very far.
The parameter of Update() is not frame.function widget:Update(frame)
See wiki for correct..Ops. On wiki it says "none", but description is ok
Re: Practice Lua Scripts
For the Lua language itself, all you need to know is on this page: http://www.lua.org/manual/5.1/
For the Spring Lua API, use all the pages linked on this page: https://springrts.com/wiki/Lua_Scripting
For the Spring Lua API, use all the pages linked on this page: https://springrts.com/wiki/Lua_Scripting
Re: Practice Lua Scripts
1 week later, still only my example. yet, the people who are quick to raise issue with it the very day I posted it, still have not given the new guy an example.
and I am the only one who sees the issue with this? Poster comes asks for help. I take the time to post a LESS THAN PERFECT EXAMPLE and instead of posting a better one, 2 posters immediately drop everything to chastise it. Why? why is this the case here? Should I post another anything ever for anyone?
and I am the only one who sees the issue with this? Poster comes asks for help. I take the time to post a LESS THAN PERFECT EXAMPLE and instead of posting a better one, 2 posters immediately drop everything to chastise it. Why? why is this the case here? Should I post another anything ever for anyone?
Re: Practice Lua Scripts
Imo there's no need to post anything else until the user shows more interest. This is OK for now.
Re: Practice Lua Scripts
I am using other resources to learn Lua. I am not trying to use Spring to learn Lua. I just like seeing examples of implementation.Imo NOT recommend to learn Lua (or even scripting) via spring, it will take longer than reading normal tutorials first.
I should have clarified what I was asking for. Not necessarily a simple code (your code is much appreciated smoth), but rather moderate code that is neat, to the point and commented. If there is no decent example that any of you know of then I am sorry for wasting your time.
Re: Practice Lua Scripts
I can't offer any, and I don't think it's wise searching for "moderate" examples at first (code usually does one specific thing). You can always look at one of the many game repos and try to figure out what's going out from there, but as said, I don't recommend it.
Also, I don't really comment my code usually if there are no special quirks.
The basics that you need to know are:
for functions widgets and gadgets can have to handle events that are invoked from the engine: https://springrts.com/wiki/Lua:Callins
for reading game objects: https://springrts.com/wiki/Lua_SyncedRead https://springrts.com/wiki/Lua_UnsyncedRead
for modifying game objects: https://springrts.com/wiki/Lua_SyncedCtrl https://springrts.com/wiki/Lua_UnsyncedCtrl
Also, I don't really comment my code usually if there are no special quirks.
The basics that you need to know are:
for functions widgets and gadgets can have to handle events that are invoked from the engine: https://springrts.com/wiki/Lua:Callins
for reading game objects: https://springrts.com/wiki/Lua_SyncedRead https://springrts.com/wiki/Lua_UnsyncedRead
for modifying game objects: https://springrts.com/wiki/Lua_SyncedCtrl https://springrts.com/wiki/Lua_UnsyncedCtrl
Re: Practice Lua Scripts
You are more than welcome to grab my repo and post stuff from any Lua file I can try and direct you towards answer on why some things are there
viewtopic.php?f=9&t=28265
viewtopic.php?f=9&t=28265
- Silentwings
- Posts: 3720
- Joined: 25 Oct 2008, 00:23
Re: Practice Lua Scripts
You've not given enough information to determine what you regard as a "moderate" example. If you linked to the examples which you had found too difficult, or gave some idea of your current knowledge, that would help. Without that all I can offer you is too look inside game repos for yourself, e.g. http://imolarpg.dyndns.org/trac/balates ... ui/widgets, https://github.com/ZeroK-RTS/Zero-K/tre ... UI/Widgets, https://springrts.com/wiki/Gamedev:PublicRepos.
Re: Practice Lua Scripts
Alot of spring people started by making widgets..
On the other hand i started - making maps.. so maybee my advice is kind of weird ..
Help is available, but not always in an instant.. join moddev.. the temple of the temptrees lua, where the mad monks sing strange songs of wright and Rongs
PS: Also dont feel ashamed or stupid to ask. I started more then clueless. Still standing. Understanding. Every day. A little more.
On the other hand i started - making maps.. so maybee my advice is kind of weird ..
Help is available, but not always in an instant.. join moddev.. the temple of the temptrees lua, where the mad monks sing strange songs of wright and Rongs
PS: Also dont feel ashamed or stupid to ask. I started more then clueless. Still standing. Understanding. Every day. A little more.
Re: Practice Lua Scripts
ldots! He's asking for a hello world widget or similar. There is some stuff here that's useful: https://springrts.com/wiki/Lua_Scriptingimboss77 wrote:I have perused scripts trying to understand what they do and they are all very complex. Are there any scripts in particular that are easier to understand for beginners?
But that links to a forum post which in turn links back to the wiki. Funny. Maybe this is how spring people think.
Moderator (gajop): User was issued for this post. https://springrts.com/wiki/Felony#1.
+ you're wrong (a basic hello world was provided and this is the answer): I should have clarified what I was asking for. Not necessarily a simple code (your code is much appreciated smoth), but rather moderate code that is neat, to the point and commented.
Re: Practice Lua Scripts
Are you insane? Why warn me for that?
Moderator (gajop): https://springrts.com/wiki/Felony#1. + https://springrts.com/wiki/Felony#4. User was warned for this post and subsequently banned for the 7day minimum.
Who did I insult? And with what?No flaming or insulting of other users, respect for all other users is mandatory and assumed regardless of post count, amount contributed, or time active.
Moderator (gajop): https://springrts.com/wiki/Felony#1. + https://springrts.com/wiki/Felony#4. User was warned for this post and subsequently banned for the 7day minimum.
Re: Practice Lua Scripts
Thank you all for your responses and help. I wish I could go full steam ahead, but sadly school isn't kind. I have a huge project I need to present this weekend, and I have to work on it this week. Thanks again for all the responses. After this weekend I'll post progress I've made.