Forum

> > CS2D > Scripts > Lua framework for CS2D?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Lua framework for CS2D?

20 replies
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

old Poll Lua framework for CS2D?

Gaios
Reviewer Off Offline

Quote
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 >


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

old Re: Lua framework for CS2D?

Gaios
Reviewer Off Offline

Quote
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:
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

old Re: Lua framework for CS2D?

Starkkz
Moderator Off Offline

Quote
@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).

old Re: Lua framework for CS2D?

DC
Admin Off Offline

Quote
@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

old Re: Lua framework for CS2D?

Infinite Rain
Reviewer Off Offline

Quote
@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.

old Re: Lua framework for CS2D?

Gaios
Reviewer Off Offline

Quote
@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.

old Re: Lua framework for CS2D?

DC
Admin Off Offline

Quote
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.

old Re: Lua framework for CS2D?

Gaios
Reviewer Off Offline

Quote
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

old Re: Lua framework for CS2D?

Vehk
User Off Offline

Quote
user Gaios has written
Example of 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 >

old Re: Lua framework for CS2D?

Starkkz
Moderator Off Offline

Quote
@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.

old Re: Lua framework for CS2D?

Vehk
User Off Offline

Quote
@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
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

old Re: Lua framework for CS2D?

Starkkz
Moderator Off Offline

Quote
@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.

old Re: Lua framework for CS2D?

Vehk
User Off Offline

Quote
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.

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).

old Re: Lua framework for CS2D?

ohaz
User Off Offline

Quote
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
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview