[Closed] Are dynamic structs possible? Reopen
Hi,
I reopen this post because it was not a bad idea.
Sometime I work in Adobe Flash Actionscript3.
And I like :
-extending classes
-is well organized and you can call them easily
It will be good to have something like this in Maxscript
Because is not easy task , I tried one different way for now
- load all desired structures at max start
- create master structure which will call any of function you wish to execute
basic idea is to have each class in separate file but instead of extending it
create new function in other file.
after that have one master structure which will call any of you function
like master.reverseArray #(1,2,3)
this should make programing more easy, whatever better idea will be welcome msx_app.rar (1.7 KB)
Struct STRUCTURE_COLLECTION_MANAGER (
public
app_dir = "",
private
ini_file = app_dir + "Struct_List.ini",
struct_names = #(), --collect structure names here
fn loadMyStructures = (
if not doesFileExist ini_file do return false
local struct_files = getINISetting ini_file "STRUCTURES"
for file_name in struct_files do (
local struct_name = getINISetting ini_file "STRUCTURES" file_name
struct_names += #(struct_name)
fileIn (app_dir + file_name + ".ms")
)
OK
),
on create do (loadMyStructures()),
public
fn run fn_str params:#() = (
format "SCM > Run > fn:% params:% cnt:%\n" fn_str params params.count
if classOf fn_str != String or classOf params != Array do return false
for s in struct_names do (
local struct_instance = execute s
if not (hasProperty struct_instance fn_str) do continue --skip structures without desired function
local prop = getProperty struct_instance fn_str
local result = case params.count of (
0: prop ()
1: prop params[1]
2: prop params[1] params[2]
3: prop params[1] params[2] params[3]
4: prop params[1] params[2] params[3] params[4]
)
return result
)
false
)
)
GLOBAL scm = STRUCTURE_COLLECTION_MANAGER app_dir:"C:\\temp\\msx_app\\"
/*
--first load all structures and collect struct instance names
--second run any of you functions by one root command
--@Example
abc = #("c", "b", "a")
scm.run "reverseArray" params:#(abc)
--@Output #("a", "b", "c")
*/
let’s talk about the reason first…
as i understand you want to put all generally used methods under one structure. … but you want originally define them in different structures (a la classes).
my objection N1:
when you design a class you also design this class name to give the sense to the name
when you design methods you do the same
the combination of both should give you the perfect sense and minimized length of final call…
check
we have an Array class (struct) collection… it make sense to name the class ArrayOps (or like that)
we have methods by meaning – Reverse Array, Merge Arrays, Filter Arrays, Intersect Arrays, ect…
we can name these methods by their meaning as there are they going
but we already have the class name with which together the names will get some ‘unnecessary details’. it makes more sense to name them like:
ArrayOps.Reverse
ArrayOps.Merge
ArrayOps.Filter
ArrayOps.Intersect
any user can get it by name
If you put these methods into abstractly named general class (like Master) the names of array methods will lose the sense (at least they will not be clear anymore). Capiche?
let’s continue talking about Advantages and Disadvantages…
many times methods defined into struct (class) belong to this class by using, and share another methods from this class…
in MXS the only way to share another methods from the struct is to work inside an instance of this struct vs its definition. There is another problem here.
MXS doesn’t give you a chance to know is it a class method or static method. So you need to specially ‘mark’ your methods (using a naming convention for example) to be able collect the right ones
Hi Denis, it is nice to hear you again, after many ears
You right, merge all structures may slow programming…
For now I’m using old way
at begin It was one idea… how to implement method of extending structures
I don’t know how is happen I make something totally different
and nonetheless… let’s return to your idea.
the task itself doesn’t make sense fort me, but it has an interesting technical element that i want to play with…
THE DYNAMIC STRUCT POSSIBILITY
I was moved on another project to make Interactive books for the children.
Most time I spend to learn acrtionscript3 in Adobe Flash.
It was good 5 years experience.
I love the class structures which is in my opinion much better than in max-script
And now I’m back in my old company 2K Czech.
It is time for resurrecting Micra Tools which is helped me a lot in past
when I look my old scripts, the first idea it was to drop it and make it all from begin
And now when is almost done I’m trying to fetch some features from action-script in to max-script
like event handler functions (live update)
mcEvents.registerEvent “VariableChanged” form.varChanged
mcEvents.dispatchEvent “VariableChanged” data:1
mcEvents.unregisterEvent “VariableChanged” form.varChanged
it’s a good idea
each time I rewrite my old tool, it becomes at least three times smaller and five times faster