FIrst, some backstory:
Cyclicaclly, I grow weary of CK2 (and other PDS games)' syntax. It is overly verbose in several ways:
The main features I would like it to have are the following:
Cyclicaclly, I grow weary of CK2 (and other PDS games)' syntax. It is overly verbose in several ways:
- The = sign is used as a mere "connective" without meaning in some cases ( add_trait = greedy ), and as ">=" in many others ( prestige = 100 ). More sensible languages would just suppress the firs use ( add_trait greedy or add_trait(greedy) ) and use the proper >= in the second.
- When a function (condition or command) has more than one argument, all the arguments are named ( has_opinion_modifier = { who = ROOT modifier = some_opinion } vs. has_opinion_modifier(ROOT, some_modifier).
- THe use of {,}, both for delimiting blocks and function arguments is confusing and makes things hard to read. Ideally, function arguments should be delimited by parenthesis or other elements.
- There's always the issue with indentation: different coders have different styles, and this, coupled with the excessive amount of brackets, make other's code somewhat unpredictable.
The main features I would like it to have are the following:
1: Indent-based blocks. Instead of separating blocks with brackets, I'll do it with the number of initia tab characters. So instead of
You would write:
2: Writing and reading code in a single line would be much easier. Instead of
You would write:
3: Quite often you need to write several conditions or commands of the same type but with different values, and I want to make this easier, so instead of
You would write:
4: Usually in programming languages the equivalent of NOT doesn't requires to use brackets or parenthesis since it only affect the next expression that appears. I want to adopt this behaviour, and adopt the usual '!' sign to mean "not". So instead of
You would write:
5: CamelCase is used to reduce the number of heystrokes and also to differentiate elements (Conditions/commands/scopes start in uppercase, values strat in lowercase).
6: Several elements are rewritten for clarity or succintness. Instead of FROMFROMFROMFROM, you'll write char:FROM_4 instead of event_target: some_title_saved_as_global_even_target, you''l write title:global:som_target
7: this means the language is type-safe: you always know when you are in character, title, province, etc, scope, by forcing to annotate the few unsafe scopes like FROM, event_targets and quest_targets.
8: dealing with variables is much less cumbersome! Write num:my_variable *= 5 instead of multiply_variable = { which = my_variable value = 5 }
9: Chaining scope changes with a single indentation. Instead of
or
you can write
10: Some common idioms will be abbreviated. For example, you can use AddTrait genius for add_trait = genius and AddTrait? genius for if = { limit = { not = { trait = genius } } } add_trait = genius } This "?-syntax" will be present for many commands that add or remove things like traits, modifiers, claims, etc. I plan on adding more as I come by common patterns. For example. I currently have a Exists <scope> that abbreviates <scope> = { always = yes } which is often used to test if a scope points to an actual object.
11: This is still very WIP, but I plan on scripted effects being able to take variables and scopes of different types as arguments, so you can do, e.g change_artifact_owner art:local:some_artifact char:local:current_owner char:local:receiver instaad of ck2script effects that only take "yes" as a possible value.
12: Syntax highlighting and autocompletions for pyCK2 on Sublime Text 3
13: In the long term, I want to translate all of the vanilla code to this pyCK2, so that it can be taken as baseline by modders who what to use the new language.
So, tell me what do you think of this initiative, wether you would be interested in using it, and any suggestions you may have to improve it.
Code:
OR = {
has_opinion_modifier = { who = ROOT modifier = some_opinion }
trait = quick[/INDENT]
}
Code:
OR:
HasOpinionTowards Root some_opinion # you can see that equal signs, brackets and names for arguments are no longer used, making both writing and reading way easier
Trait quick
Code:
OR = { is_ruler = yes has_opinion_modifier = { who = ROOT modifier = some_opinion } trait = quick }
Code:
OR: IsRuler; HasOpinionTowards Root some_opinion; Trait quick
#you can see that several simple conditions are separated by ';', the OR: encompases the whole line, only a single block (or, and, limit, etc.) can be used in a single line like this. If you need to use more lines you could write them like in the previous example.
Code:
OR = { trait = genius trait = quick trait = brave trait = fair is_ruler = yes }
Code:
OR: Trait genius, quick, brave, fair; IsRuler
# several instances of the same condition with different values are separated with ',' and you only write the values, not the name of the condition/command.
Code:
OR = { NOT = { trait = genius } NOT = { trait = quick } trait = brave trait = fair is_ruler = yes }
Code:
OR: Trait ! genius, ! quick, brave, fair; ! IsRuler
# Additionally note that conditions that only take yes or no in ck2script take no arguments in pyCK2, isRuler equals is_ruler = yes and ! IsRuler equals is_ruler = no.
5: CamelCase is used to reduce the number of heystrokes and also to differentiate elements (Conditions/commands/scopes start in uppercase, values strat in lowercase).
6: Several elements are rewritten for clarity or succintness. Instead of FROMFROMFROMFROM, you'll write char:FROM_4 instead of event_target: some_title_saved_as_global_even_target, you''l write title:global:som_target
7: this means the language is type-safe: you always know when you are in character, title, province, etc, scope, by forcing to annotate the few unsafe scopes like FROM, event_targets and quest_targets.
8: dealing with variables is much less cumbersome! Write num:my_variable *= 5 instead of multiply_variable = { which = my_variable value = 5 }
9: Chaining scope changes with a single indentation. Instead of
Code:
scope1 = {
scope2 = {
scope3 = {
scope4 = {
effects
}
}
}
}
Code:
scope1 = { scope2 = { scope3 = { scope4 = {
effects
}}}}
Code:
scope1: scope2: scope3: scope4:
effects
10: Some common idioms will be abbreviated. For example, you can use AddTrait genius for add_trait = genius and AddTrait? genius for if = { limit = { not = { trait = genius } } } add_trait = genius } This "?-syntax" will be present for many commands that add or remove things like traits, modifiers, claims, etc. I plan on adding more as I come by common patterns. For example. I currently have a Exists <scope> that abbreviates <scope> = { always = yes } which is often used to test if a scope points to an actual object.
11: This is still very WIP, but I plan on scripted effects being able to take variables and scopes of different types as arguments, so you can do, e.g change_artifact_owner art:local:some_artifact char:local:current_owner char:local:receiver instaad of ck2script effects that only take "yes" as a possible value.
12: Syntax highlighting and autocompletions for pyCK2 on Sublime Text 3
13: In the long term, I want to translate all of the vanilla code to this pyCK2, so that it can be taken as baseline by modders who what to use the new language.
So, tell me what do you think of this initiative, wether you would be interested in using it, and any suggestions you may have to improve it.