English Lua framework for CS2D?

20 replies
Goto Page
To the start Previous 1 2 Next To the start
Poll Poll
Do you want such tutorial?
Only registered users are allowed to vote
✔ Yes
65.38% (17)
✖ No
7.69% (2)
I don't care
26.92% (7)
26 votes cast
26.10.17 12:34:00 pm
Up
Gaios
Security Supporter
Offline Off
Would anybody like to learn how to write professional code on example of CS2D and learn logical programming to write beautiful code?

I'm going to write Lua framework for CS2D, and then record tutorial at YouTube. Please vote to tell me know
More >


Code:
1
2
3
4
5
6
7
8
9
10
11
12
class Idea extends Eloquent
{

     /**
      * Dreaming of something more?
      */
     public function create()
     {
          // Have a fresh start...
     }

}


> https://github.com/gajosadrian/Gajos-Framework
edited 2×, last 13.11.17 03:50:14 pm
26.10.17 06:37:18 pm
Up
Bowlinghead
User
Offline Off
I like it. Would pay for this (not much though)!

Will you create datatypes? (int, boolean,...)
Will you add operators?
Share time limited free games here
26.10.17 08:21:54 pm
Up
Gaios
Security Supporter
Offline Off
I just realized that making such language is like create compilator which will translate such code to Lua - I don't want to do that.

I'm going to focus at Lua language. Lua has undefined datatypes (it's pretty handy) and operators ofc.

Example of code:
Code:
1
2
3
4
function onPlayerSay(<model> user, <string> message)
    print('Player' .. user.name .. ' stands at ' .. user.x .. '-' .. user.y)
    user:ChangePos(0, 0)
end


IMG:https://image.slidesharecdn.com/modelviewcontrollermvc-140211001124-phpapp01/95/model-view-controller-mvc-6-638.jpg?cb=1392077579
edited 2×, last 27.10.17 08:41:30 am
26.10.17 08:39:18 pm
Up
Starkkz
Moderator
Offline Off
@user Gaios: though translating is not a bad approach since you'd be getting the language performance as a profit. What makes that kind of syntax so special is how strict it is.

You can still work with Lua's existing data types + add flexible features which would allow different type of objects to work with it (userdata/tables/etc).
lol
27.10.17 11:08:36 am
Up
Infinite Rain
Reviewer
Offline Off
I'm sorry, MVC for CS2D scripting? That doesn't make sense. MVC is a paradigm used primarily for web development. Or am I wrong?
A thousand may fall at your side, ten thousand at your right hand, but it will not come near you. You will only look with your eyes and see the recompense of the wicked. - Psalm 91:7-8 ESV
27.10.17 11:21:12 am
Up
DC
Admin
Offline Off
@user Infinite Rain: No, MVC works for non-web applications with UI and therefore games as well.

In CS2D you are already forced to use a decoupled interface - the built in CS2D Lua API. You should ask yourself: What is the reason to add another layer of abstraction / decoupling? Is it necessary? What are the benefits? What are the downsides?

Some thoughts regarding this: In my opinion most CS2D scripts are not complex enough to justify the additional overhead (development and runtime) that comes with MVC. Be aware that MVC - in most cases - means that you have to write tons of additional boilerplate code. So you need to do more work to achieve the same thing. Plus your scripts may become slower (in most cases this won't have a real impact though).

On the other hand however there are reasons to use MVC. E.g. if you write a super complex script with a very fancy UI and you want to be able to easily replace/change that UI without touching the actual logic of the script. I think this rarely happens with CS2D scripts though.

I would never use MVC for CS2D scripts but that's just my opinion.
What I actually want to say: Don't use MVC only for the sake of using MVC.

But of course if you're using the whole thing just to demonstrate what MVC is and how it works it's a different story
edited 2×, last 27.10.17 11:36:42 am
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
27.10.17 11:44:48 am
Up
Infinite Rain
Reviewer
Offline Off
@user DC:

Well, that's why I said "primarily". Web development has a high level of complexity, so that's why the MVC paradigm is used.

I just don't see the point in implementing it into CS2D.
A thousand may fall at your side, ten thousand at your right hand, but it will not come near you. You will only look with your eyes and see the recompense of the wicked. - Psalm 91:7-8 ESV
27.10.17 12:16:42 pm
Up
Gaios
Security Supporter
Offline Off
@user DC: Do you know any good pattern designs for games? What do you use in Stranded III? I don't like abstract pattern, and factory pattern isn't much good for big projects.

I just starded to use Visual Lua -> GUI and I'm forced to implement any good pattern design.
27.10.17 04:05:37 pm
Up
DC
Admin
Offline Off
Most of the time I don't think about patterns. I think about solutions. If I have a problem I try to come up with a solution which seems to fit best for the specific problem.

In the end my code might use established patterns. It's also possible though that it is just some stuff which does not use a well known software design pattern.

It's hard to just list some patterns because it really depends completely on the specific problem you want to solve.
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
27.10.17 05:35:41 pm
Up
ohaz
User
Offline Off
Maybe you guys should read Clean Code by Robert C. Martin
https://ohaz.engineer - Software Engineering
27.10.17 07:58:42 pm
Up
Gaios
Security Supporter
Offline Off
@user ohaz: Wow thx, I'm going to buy this book.
27.10.17 08:34:24 pm
Up
tontonEd
User
Offline Off
MVP makes codes cleaner, it's takes times to get it in place but you save a lot of time in futur.

I've modelised class such buttons/menu using 'Yet Another Class Implementation' see here
http://unrealsoftware.de/files_show.php?file=16689&showcontents=1

goodluck
27.10.17 11:48:16 pm
Up
Gaios
Security Supporter
Offline Off
Model-View-Controller - this architecture is just very common in game developing but nobody really cares.

1. Application Layer (Controller)
The application layer deals with devices, operating systems and the game lifetime. This is where input and memory is managed. The game is initialized and shut down in the application layer.

2. Game Logic (Model)
Game logic is where the life of the game resides. This is where the game world or universe is defined. Each object existence in the game and how it acts and interacts is defined here.

3. Game View (View)
It is fairly standard that in large scale game projects most of the budget could go on graphic. The view process manager is similar to the one one in the application layer but controls functions like button animations and media streaming.

> https://slideshare.net/Ruairi/comparing-game-development-on-the-android-and-windows-phone-7-platforms
28.10.17 10:29:30 pm
Up
Vehk
User
Offline Off
user Gaios has written:
Example of code:
Code:
1
2
3
4
function onPlayerSay(<model> user, <string> message)
    print('Player' .. user.name .. ' stands at ' .. user.x .. '-' .. user.y)
    user:ChangePos(0, 0)
end


I was working on something similar a few weeks ago. I've got most of it done. If you want I can upload the code.

As an example I re-wrote samples/gungame.lua

More >
07.11.17 10:49:13 am
Up
Gaios
Security Supporter
Offline Off
EDIT:
Ok, I just got want I want, https://pl.wikipedia.org/wiki/JavaBeans. But...

Shoud I use getters and setters:
user.x = newx; user.y = newy
or better is
user:setX(newx); user:setY(newy)
? What is better and more modern?
edited 2×, last 08.11.17 08:12:17 am
08.11.17 03:26:06 pm
Up
Starkkz
Moderator
Offline Off
@user Gaios: The problem with Lua is that it doesn't whine when you write the attribute incorrectly. For example,
self.Color
instead of
self.color
. I prefer using setter/getters, if a setter/getter is missing, it's going to tell you.
lol
12.11.17 09:14:52 pm
Up
Vehk
User
Offline Off
@user Starkkz:
Lua can do that.
More >


You could remove the __newindex metamethod to allow new keys to be added.

Also, you could make keys case-insensitive
Code:
1
2
3
4
5
6
7
8
9
function index(t, k)
     k = k:lower()
     return rawget(t, k)
end

function newindex(t, k, v)
     k = k:lower()
     return rawset(t, k, v)
end
edited 1×, last 12.11.17 09:38:18 pm
12.11.17 09:58:20 pm
Up
Starkkz
Moderator
Offline Off
@user Vehk: If you want to go through a long discussion on how many things you can do with Lua, it would be endless. My point is that you have to make workarounds for that, they're not native features, therefore dirty.

It's annoying to have to copy + paste that code on every class you make.
lol
12.11.17 10:30:23 pm
Up
Vehk
User
Offline Off
user Starkkz has written:
It's annoying to have to copy + paste that code on every class you make.

Lua doesn't have classes. And the problem is solved more simply by just typing the correct name.

user Starkkz has written:
The problem with Lua is that it doesn't whine when you write the attribute incorrectly. For example,
self.Color
instead of
self.color


It will whine if you try to do almost anything with a nil value.

Code:
1
msg(self.Color .. "message")


output has written:
stdin:1: attempt to concatenate a nil value (field 'Color')


user Gaios has written:
What is better and more modern?

I like the first better. I don't see a reason to do it the second way.

More >


With that you have what you need to make pl.xyz work with several values (x, y, health, armor, etc.). More is needed to make it more seamlessly integrated into CS2D Lua (making hooks create the table automatically).

I think you should use the first way for when you are setting values and the second when you are doing something to the player (like cs2d cmd flashplayer or cs2d cmd equip).
13.11.17 07:57:29 am
Up
ohaz
User
Offline Off
Using setX and setY instead of directly accessing the variable has multiple advantages:

• you can do certain checks when setting, e.g. boundary checks
• when there is a change in the API (e.g. the name of x changes), you can still keep the old setters and thus have backwards-compatibility
• You can create fluentAPIs
https://ohaz.engineer - Software Engineering
To the start Previous 1 2 Next To the start