[Suggestion] Hashtables (or associative arrays) and variants

You can talk about ManiaScript for ManiaPlanet here

Moderator: English Moderator

Post Reply
User avatar
TGYoshi
Posts: 795
Joined: 15 Mar 2011, 16:59

[Suggestion] Hashtables (or associative arrays) and variants

Post by TGYoshi »

Don't get me started on why the hell the language ever got published without some way to create custom key -> value mapped objects, but here's my suggestion to finally add such a feature. It's seriously essential to keep code relatively clean.

Ever seen the top of the animation stop function of the Manialink lib? I feel sorry for the guy who had to hack it this way:

Code: Select all

Void LibManialink_AnimStop(CMlControl _Control, Integer _AnimId) {
	declare Integer[Integer] LibManialink_AnimQueue for _Control;
	
	declare Integer[Integer]	LibManialink_AnimStarTime		for _Control;
	declare Integer[Integer]	LibManialink_AnimDuration		for _Control;
	declare Integer[Integer]	LibManialink_AnimEndTime		for _Control;
	declare Text[Integer]		LibManialink_AnimEasing			for _Control;
	declare Text[Integer]		LibManialink_Visibility			for _Control;
	declare Boolean[Integer]	LibManialink_AnimRunning		for _Control;
	declare Integer[Integer]	LibManialink_AnimStyle			for _Control;
	declare Boolean[][Integer]	LibManialink_AnimActive			for _Control;
	declare Integer[Integer]	LibManialink_AnimReapeatTime	for _Control;
	declare Integer[Integer]	LibManialink_AnimReapeatNb		for _Control;
	
	declare Vec3[Integer]		LibManialink_AnimStart_Position	for _Control;
	declare Vec2[Integer]		LibManialink_AnimStart_Size		for _Control;
	declare Real[Integer]		LibManialink_AnimStart_Scale	for _Control;
	declare Real[Integer]		LibManialink_AnimStart_Rotation	for _Control;
	declare Real[Integer]		LibManialink_AnimStart_Opacity	for _Control;
	declare Vec3[Integer]		LibManialink_AnimStart_Colorize	for _Control;
	declare Vec3[Integer]		LibManialink_AnimStart_BgColor	for _Control;
	declare Vec3[Integer]		LibManialink_AnimStart_TextColor for _Control;
	declare Real[Integer]		LibManialink_AnimStart_Ratio	for _Control;
	declare Vec3[Integer]		LibManialink_AnimStart_GaugeColor for _Control;
	
	declare Vec3[Integer]		LibManialink_AnimEnd_Position	for _Control;
	declare Vec2[Integer]		LibManialink_AnimEnd_Size		for _Control;
	declare Real[Integer]		LibManialink_AnimEnd_Scale		for _Control;
	declare Real[Integer]		LibManialink_AnimEnd_Rotation	for _Control;
	declare Real[Integer]		LibManialink_AnimEnd_Opacity	for _Control;
	declare Vec3[Integer]		LibManialink_AnimEnd_Colorize	for _Control;
	declare Vec3[Integer]		LibManialink_AnimEnd_BgColor	for _Control;
	declare Vec3[Integer]		LibManialink_AnimEnd_TextColor	for _Control;
	declare Real[Integer]		LibManialink_AnimEnd_Ratio		for _Control;
	declare Vec3[Integer]		LibManialink_AnimEnd_GaugeColor	for _Control;
	
	declare Vec3[Integer]		LibManialink_AnimDiff_Position	for _Control;
	declare Vec2[Integer]		LibManialink_AnimDiff_Size		for _Control;
	declare Real[Integer]		LibManialink_AnimDiff_Scale		for _Control;
	declare Real[Integer]		LibManialink_AnimDiff_Rotation	for _Control;
	declare Real[Integer]		LibManialink_AnimDiff_Opacity	for _Control;
	declare Vec3[Integer]		LibManialink_AnimDiff_Colorize	for _Control;
	declare Vec3[Integer]		LibManialink_AnimDiff_BgColor	for _Control;
	declare Vec3[Integer]		LibManialink_AnimDiff_TextColor	for _Control;
	declare Real[Integer]		LibManialink_AnimDiff_Ratio		for _Control;
	declare Vec3[Integer]		LibManialink_AnimDiff_GaugeColor for _Control;

...
Imagine if could declare a hashtable and just store an array of hashtables per control representing the queue, each hashtable representing some data about that specific animation. Hashtable values should be allowed to be a variant for this to be most effective, although this does reduce the amount of typechecking possible in the language. There are arguably better alternatives, like actual custom structures.

In the end it's seriously a pain to work without any way to declare custom structures. One way to support this are hashtables and variants, but a lot of things will do. A better way is of course defining an API for an existing language, but since Nadeo prefers to reinvent the wheel, this won't happen ;).

Large things like this and a lacking API make ManiaScript much less powerful than it can be.
=3
User avatar
maxi031
Posts: 378
Joined: 17 Jul 2011, 00:55

Re: [Suggestion] Hashtables (or associative arrays) and vari

Post by maxi031 »

I support this all the way, custom structures would be great addition to the maniascript. :clap:
My specs:
MOBO: MB AM3+ 970 Gigabyte GA-970A-DS3P
CPU: AM3+ AMD FX-8320E
GPU: Nvidia GeForce GTX750-Ti ASUS 2GB DDR5
RAM: DDR3 8GB 1866MHz Kingston HyperX
SSD: SATA3 120gb SanDisk
OS: Ubuntu 19.04
TY MICMO
zocka
Posts: 205
Joined: 15 Jun 2010, 17:56

Re: [Suggestion] Hashtables (or associative arrays) and vari

Post by zocka »

Code: Select all

Integer[Integer] /* or */ Integer[Text]
are associative arrays (or hashtables) or do I have a different idea about how hashtables work? :D

What you suggest sounds a bit like that to me:

Code: Select all

MyStructure[_Instance] = ["key1"=>42, "key2"=>"foo", "key3"=>False];
That looks really bad in my eyes :D

Structs could be really well readable I think, but might be a pain to implement.

I got used to just return a handle with my "constructor" functions, which I then give to all the "methods" and have this handle as array key for their "property" values. It might not be the best programing pattern, but it's the best as ManiaScript currently is and it's not that bad if you get used to it and format your code in a nice way :P

(When you declare the handle with implicit type, you don't even have to bother that it's just an ugly handle :D)

Code: Select all

declare MyJSONObject = JSON_Parse(MyJSONstring);
declare SomeKey = JSON_GetObject(MyJSONObject, "somekey");
That's not that bad to actually use :D


Well I kind of try to create easy to use library functions and work around those issues, but when I use them I'm happy I went for the effort, maybe that's not representative for someone creating gamemodes etc :roll:
manialink minigame shatter
my manialink: zockaml
my maniaflash: maniaflash?zocka
oliverde8
Posts: 1286
Joined: 16 Jun 2010, 07:33
Location: in a Blue Box

Re: [Suggestion] Hashtables (or associative arrays) and vari

Post by oliverde8 »

maniascript a language? I thought it was a joke.

structures would be a great addition, why we are at it can we also have function pointers?
(yes I like my variables of type void* points to functions)
Image
Developper for The next generation, Clean and Powerfull controller eXpansion for your SM & TM server . Working on eXpansion² with full MP4 support and many other awesome features...
Post Reply

Return to “ManiaScript”

Who is online

Users browsing this forum: No registered users and 2 guests