123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532 |
- #LyX 2.0 created this file. For more info see http://www.lyx.org/
- \lyxformat 413
- \begin_document
- \begin_header
- \textclass article
- \use_default_options true
- \maintain_unincluded_children false
- \language english
- \language_package default
- \inputencoding auto
- \fontencoding global
- \font_roman default
- \font_sans default
- \font_typewriter default
- \font_default_family default
- \use_non_tex_fonts false
- \font_sc false
- \font_osf false
- \font_sf_scale 100
- \font_tt_scale 100
- \graphics default
- \default_output_format default
- \output_sync 0
- \bibtex_command default
- \index_command default
- \paperfontsize default
- \use_hyperref false
- \papersize default
- \use_geometry false
- \use_amsmath 1
- \use_esint 1
- \use_mhchem 1
- \use_mathdots 1
- \cite_engine basic
- \use_bibtopic false
- \use_indices false
- \paperorientation portrait
- \suppress_date false
- \use_refstyle 0
- \index Index
- \shortcut idx
- \color #008000
- \end_index
- \secnumdepth 3
- \tocdepth 3
- \paragraph_separation indent
- \paragraph_indentation default
- \quotes_language english
- \papercolumns 1
- \papersides 1
- \paperpagestyle default
- \tracking_changes false
- \output_changes false
- \html_math_output 0
- \html_css_as_file 0
- \html_be_strict false
- \end_header
- \begin_body
- \begin_layout Title
- GD Scripting Language (GDScript)
- \end_layout
- \begin_layout Section
- Introduction
- \end_layout
- \begin_layout Standard
- GDScript is a high level, dynamically typed programming language used to
- create content.
- It uses a syntax that is very similar to the Python language (blocks are
- indent-based) and it's goal is to be very optimal and tigthly integrated
- with the engine, allowing great flexibility for content creation and integratio
- n.
-
- \end_layout
- \begin_layout Section
- Example
- \end_layout
- \begin_layout Standard
- Some people can learn better by just taking a look at the syntax, so here's
- a simple example of how it looks.
-
- \end_layout
- \begin_layout Standard
- \begin_inset listings
- inline false
- status open
- \begin_layout Plain Layout
- #a file is a class!
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- #inheritance
- \end_layout
- \begin_layout Plain Layout
- extends BaseClass
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- #member variables
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- var a=5
- \end_layout
- \begin_layout Plain Layout
- var s="Hello"
- \end_layout
- \begin_layout Plain Layout
- var arr=[1,2,3]
- \end_layout
- \begin_layout Plain Layout
- var dict={"key":"value", 2:3}
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- #constants
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- const answer=42
- \end_layout
- \begin_layout Plain Layout
- const thename="Charly"
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- #built-in vector types
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- var v2 = Vector2(1,2)
- \end_layout
- \begin_layout Plain Layout
- var v3 = Vector3(1,2,3)
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- #function
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- func some_function(param1,param2):
- \end_layout
- \begin_layout Plain Layout
- var local_var=5
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- if param1 < local_var:
- \end_layout
- \begin_layout Plain Layout
- print(param1)
- \end_layout
- \begin_layout Plain Layout
- elif param2 > 5:
- \end_layout
- \begin_layout Plain Layout
- print(param2)
- \end_layout
- \begin_layout Plain Layout
- else:
- \end_layout
- \begin_layout Plain Layout
- print("fail!")
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- for i in range(20):
- \end_layout
- \begin_layout Plain Layout
- print(i)
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- while(param2!=0):
- \end_layout
- \begin_layout Plain Layout
- param2-=1
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- var local_var2 = param1+3
- \end_layout
- \begin_layout Plain Layout
- return local_var2
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- #subclass
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- class Something:
- \end_layout
- \begin_layout Plain Layout
- var a=10
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- #constructor
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- func _init():
- \end_layout
- \begin_layout Plain Layout
- print("constructed!")
- \end_layout
- \begin_layout Plain Layout
- var lv = Something.new()
- \end_layout
- \begin_layout Plain Layout
- print(lv.a)
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \end_inset
- \end_layout
- \begin_layout Section
- Language
- \end_layout
- \begin_layout Subsection
- Identifiers
- \end_layout
- \begin_layout Standard
- Any string that restricts itself to alphabetic characters ('a' to 'z' and
- 'A' to 'Z'), digits ('0' to '9') and '_' qualifies as an identifier.
- As an extra restriction, identifiers must not begin with a digit.
- Identifiers are case-sensitive ('foo' is different to 'FOO').
- \end_layout
- \begin_layout Subsection
- Keywords
- \end_layout
- \begin_layout Standard
- The following is the list of keywords supported by the language.
- Since keywords are reserved words (tokens), they can't be used as identifiers.
- \end_layout
- \begin_layout Subsection
- Operators
- \end_layout
- \begin_layout Standard
- The following is the list of supported operators and their precedence (TODO,
- change since this was made to reflect python operators)
- \end_layout
- \begin_layout Standard
- \begin_inset Tabular
- <lyxtabular version="3" rows="18" columns="2">
- <features tabularvalignment="middle">
- <column alignment="center" valignment="top" width="0">
- <column alignment="center" valignment="top" width="0">
- <row>
- <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Operator
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Note
- \end_layout
- \end_inset
- </cell>
- </row>
- <row>
- <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- x[index]
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Subscription, Highest Priority
- \end_layout
- \end_inset
- </cell>
- </row>
- <row>
- <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- x.attribute
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Attribute Reference
- \end_layout
- \end_inset
- </cell>
- </row>
- <row>
- <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- extends
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Instance Type Checker
- \end_layout
- \end_inset
- </cell>
- </row>
- <row>
- <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- ~
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Bitwise NOT
- \end_layout
- \end_inset
- </cell>
- </row>
- <row>
- <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- -x
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Negative
- \end_layout
- \end_inset
- </cell>
- </row>
- <row>
- <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- * / %
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Mult / Div / Remainder
- \end_layout
- \end_inset
- </cell>
- </row>
- <row>
- <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- + -
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Addition / Substraction
- \end_layout
- \end_inset
- </cell>
- </row>
- <row>
- <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- << >>
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Bit Shifting
- \end_layout
- \end_inset
- </cell>
- </row>
- <row>
- <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- &
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Bitwise AND
- \end_layout
- \end_inset
- </cell>
- </row>
- <row>
- <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- ^
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Bitwise XOR
- \end_layout
- \end_inset
- </cell>
- </row>
- <row>
- <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- |
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Bitwise OR
- \end_layout
- \end_inset
- </cell>
- </row>
- <row>
- <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- < > == != >= <=
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Comparisons
- \end_layout
- \end_inset
- </cell>
- </row>
- <row>
- <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- in
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Content Test
- \end_layout
- \end_inset
- </cell>
- </row>
- <row>
- <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- ! not
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Boolean NOT
- \end_layout
- \end_inset
- </cell>
- </row>
- <row>
- <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- and &&
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Boolean AND
- \end_layout
- \end_inset
- </cell>
- </row>
- <row>
- <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- or ||
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Boolean OR
- \end_layout
- \end_inset
- </cell>
- </row>
- <row>
- <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- = += -= *= /= ^= &= |=
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Assignment, Lowest Priority
- \end_layout
- \end_inset
- </cell>
- </row>
- </lyxtabular>
- \end_inset
- \end_layout
- \begin_layout Subsection
- Literals
- \end_layout
- \begin_layout Standard
- \begin_inset Tabular
- <lyxtabular version="3" rows="6" columns="2">
- <features tabularvalignment="middle">
- <column alignment="center" valignment="top" width="0">
- <column alignment="center" valignment="top" width="0">
- <row>
- <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Literal
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Name
- \end_layout
- \end_inset
- </cell>
- </row>
- <row>
- <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- 45
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Base 10 Integer
- \end_layout
- \end_inset
- </cell>
- </row>
- <row>
- <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- 0x8F51
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Base 16 (hex) Integer
- \end_layout
- \end_inset
- </cell>
- </row>
- <row>
- <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- 3.14, 58.1e-10
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Floating Point Number (real)
- \end_layout
- \end_inset
- </cell>
- </row>
- <row>
- <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- 'Hello',
- \begin_inset Quotes eld
- \end_inset
- Hi
- \begin_inset Quotes erd
- \end_inset
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Strings
- \end_layout
- \end_inset
- </cell>
- </row>
- <row>
- <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- @'Hello', @'Hi'
- \end_layout
- \end_inset
- </cell>
- <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
- \begin_inset Text
- \begin_layout Plain Layout
- Internationalized Strings
- \end_layout
- \end_inset
- </cell>
- </row>
- </lyxtabular>
- \end_inset
- \end_layout
- \begin_layout Subsection
- Comments
- \end_layout
- \begin_layout Standard
- Anything from a '#' to the end of the line is ignored and is considered
- a comment.
- \end_layout
- \begin_layout Standard
- \begin_inset listings
- lstparams "language=Python"
- inline false
- status open
- \begin_layout Plain Layout
- # This is a comment
- \end_layout
- \end_inset
- \end_layout
- \begin_layout Section
- Built-in Types
- \end_layout
- \begin_layout Subsection
- Basic Bult-In Types
- \end_layout
- \begin_layout Standard
- A variable in GDScript can be assigned many of several built-in types.
-
- \end_layout
- \begin_layout Subsubsection
- null
- \end_layout
- \begin_layout Standard
- 'null' is a data type that contains no information, nothing assigned, and
- it's just empy.
- It can only be set to one value: 'null'.
- \end_layout
- \begin_layout Subsubsection
- bool
- \end_layout
- \begin_layout Standard
- Boolean data type, can only contain 'true' or 'false'.
- \end_layout
- \begin_layout Subsubsection
- int
- \end_layout
- \begin_layout Standard
- Integer data type, can only contain integer numbers, negative and positive.
- \end_layout
- \begin_layout Subsubsection
- float
- \end_layout
- \begin_layout Standard
- contains a floating point value (real).
- \end_layout
- \begin_layout Subsubsection
- String
- \end_layout
- \begin_layout Standard
- Sequence of characters in unicode format.
- Strings can contain the standard C escape sequences.
- \end_layout
- \begin_layout Subsection
- Vector Built-In Types
- \end_layout
- \begin_layout Subsubsection
- Vector2/Size2
- \end_layout
- \begin_layout Standard
- 2D vector type, containing x and y fields.
- Can alternatively access fields as width and height for readability.
- Can also be accessed as array.
- \end_layout
- \begin_layout Subsubsection
- Rect2
- \end_layout
- \begin_layout Standard
- 2D Rectangle type.
- Contains 2 vectors fields,
- \begin_inset Quotes eld
- \end_inset
- pos
- \begin_inset Quotes erd
- \end_inset
- and size
- \begin_inset Quotes erd
- \end_inset
- .
- Alternatively contains an
- \begin_inset Quotes eld
- \end_inset
- end
- \begin_inset Quotes erd
- \end_inset
- field which is
- \begin_inset Quotes eld
- \end_inset
- pos+size
- \begin_inset Quotes erd
- \end_inset
- .
- \end_layout
- \begin_layout Subsubsection
- Vector3
- \end_layout
- \begin_layout Standard
- 3D vector type.
- Contains x, y and z fields.
- Can also be accessed as array.
- \end_layout
- \begin_layout Subsubsection
- Matrix32
- \end_layout
- \begin_layout Standard
- 3x2 matrix used for 2D transforms.
- \end_layout
- \begin_layout Subsubsection
- Plane
- \end_layout
- \begin_layout Standard
- 3D Plane type in normalized form.
- Contains a
- \begin_inset Quotes eld
- \end_inset
- normal
- \begin_inset Quotes erd
- \end_inset
- vector field and a
- \begin_inset Quotes eld
- \end_inset
- d
- \begin_inset Quotes erd
- \end_inset
- scalar distance.
- \end_layout
- \begin_layout Subsubsection
- Quat
- \end_layout
- \begin_layout Standard
- Quaternion, datatype used for representing a 3D rotation.
- It's useful for interpolating rotations.
- \end_layout
- \begin_layout Subsubsection
- AABB/Box3
- \end_layout
- \begin_layout Standard
- Axis Aligned bounding box (or alternatively, 3D box).
- Contains 2 vectors fields,
- \begin_inset Quotes eld
- \end_inset
- pos
- \begin_inset Quotes erd
- \end_inset
- and size
- \begin_inset Quotes erd
- \end_inset
- .
- Alternatively contains an
- \begin_inset Quotes eld
- \end_inset
- end
- \begin_inset Quotes erd
- \end_inset
- field which is
- \begin_inset Quotes eld
- \end_inset
- pos+size
- \begin_inset Quotes erd
- \end_inset
- .
- \end_layout
- \begin_layout Subsubsection
- Matrix3
- \end_layout
- \begin_layout Standard
- 3x3 matrix used for 3D rotation and scale.
- Contains 3 vector fields x,y and z.
- Can also be accessed as array of 3D vectors.
- \end_layout
- \begin_layout Subsubsection
- Transform
- \end_layout
- \begin_layout Standard
- 3D Transform, contains a Matrix3 field
- \begin_inset Quotes eld
- \end_inset
- basis
- \begin_inset Quotes erd
- \end_inset
- and a Vector3 field
- \begin_inset Quotes eld
- \end_inset
- origin
- \begin_inset Quotes erd
- \end_inset
- .
- \end_layout
- \begin_layout Subsection
- Engine Built-In Types
- \end_layout
- \begin_layout Subsubsection
- Color
- \end_layout
- \begin_layout Standard
- Color datatype, contains r,g,b,a fields.
- Can also be accessed as h,s,v for hue/saturation/value.
- \end_layout
- \begin_layout Subsubsection
- Image
- \end_layout
- \begin_layout Standard
- Contains a 2D Image of custom format and allows direct access to the pixels.
- \end_layout
- \begin_layout Subsubsection
- NodePath
- \end_layout
- \begin_layout Standard
- Compiled path to a node, used mainly in the scene system.
- Can be easily asigned from/to a String.
- \end_layout
- \begin_layout Subsubsection
- RID
- \end_layout
- \begin_layout Standard
- Resource ID (RID).
- Servers use generic RIDs to reference opaque data.
- \end_layout
- \begin_layout Subsubsection
- Object
- \end_layout
- \begin_layout Standard
- Base class for anything not a built-in type.
-
- \end_layout
- \begin_layout Subsubsection
- InputEvent
- \end_layout
- \begin_layout Standard
- Events from input devices are contained in very compact form in InputEvent
- objects.
- Due to fact they can be received in high amounts from frame to frame, they
- are optimized in their own datatype.
-
- \end_layout
- \begin_layout Subsection
- Container Built-In Types
- \end_layout
- \begin_layout Subsubsection
- Array
- \end_layout
- \begin_layout Standard
- Generic sequence of objects.
- It's size can be changed to anything and starts from index 0.
-
- \end_layout
- \begin_layout Standard
- \begin_inset listings
- inline false
- status open
- \begin_layout Plain Layout
- var arr=[]
- \end_layout
- \begin_layout Plain Layout
- arr=[1,2,3]
- \end_layout
- \begin_layout Plain Layout
- arr[0]="Hi!"
- \end_layout
- \end_inset
- \end_layout
- \begin_layout Standard
- Arrays are allocated linearly in memory, so they are fast, but very large
- arrays (more than tens of thousands of elements) may cause fragmentation.
- There are specialized arrays for some built-in datatypes which do not suffer
- from this and use much less memory.
- \end_layout
- \begin_layout Subsubsection
- Dictionary
- \end_layout
- \begin_layout Standard
- Associative container which contains values referenced by unique keys.
- \end_layout
- \begin_layout Standard
- \begin_inset listings
- inline false
- status open
- \begin_layout Plain Layout
- var dict={4:5, "a key":"a value", 28:[1,2,3]}
- \end_layout
- \begin_layout Plain Layout
- dict["Hi!"]=0
- \end_layout
- \end_inset
- \end_layout
- \begin_layout Subsubsection
- ByteArray
- \end_layout
- \begin_layout Standard
- Array of bytes.
- Can only contains bytes (integers from 0 to 255).
- Optimized for memory usage, can't fragment the memory.
- \end_layout
- \begin_layout Subsubsection
- IntArray
- \end_layout
- \begin_layout Standard
- Array of integers.
- Can only contain integers.
- Optimized for memory usage, can't fragment the memory.
- \end_layout
- \begin_layout Subsubsection
- FloatArray
- \end_layout
- \begin_layout Standard
- Array of floats, can only contain floats.
- Optimized for memory usage, can't fragment the memory.
- \end_layout
- \begin_layout Subsubsection
- StringArray
- \end_layout
- \begin_layout Standard
- Array of strings, can only contain strings.
- Optimized for memory usage, can't fragment the memory.
- \end_layout
- \begin_layout Subsubsection
- Vector2Array
- \end_layout
- \begin_layout Standard
- Array of Vector2, can only contain 2D Vectors.
- Optimized for memory usage, can't fragment the memory.
- \end_layout
- \begin_layout Subsubsection
- Vector3Array
- \end_layout
- \begin_layout Standard
- Array of Vector3, can only contain 3D Vectors.
- Optimized for memory usage, can't fragment the memory.
- \end_layout
- \begin_layout Subsubsection
- ColorArray
- \end_layout
- \begin_layout Standard
- Array of Color, can only contains colors.
- Optimized for memory usage, can't fragment the memory.
- \end_layout
- \begin_layout Section
- Data
- \end_layout
- \begin_layout Subsection
- Variables
- \end_layout
- \begin_layout Standard
- Variables can exist as class members or local to functions.
- They are created with the
- \begin_inset Quotes eld
- \end_inset
- var
- \begin_inset Quotes erd
- \end_inset
- keyword and may be, optionally, be assigned a value upon initialization.
- \end_layout
- \begin_layout Standard
- \begin_inset listings
- inline false
- status open
- \begin_layout Plain Layout
- var a # datatype is null by default
- \end_layout
- \begin_layout Plain Layout
- var b = 5
- \end_layout
- \begin_layout Plain Layout
- var c = 3.8
- \end_layout
- \begin_layout Plain Layout
- var d = b+c # variables are always initialized in order
- \end_layout
- \end_inset
- \end_layout
- \begin_layout Subsection
- Constants
- \end_layout
- \begin_layout Standard
- Constants are similar to variables, but must be constants or constant expression
- s and must be assigned on initialization.
- \end_layout
- \begin_layout Standard
- \begin_inset listings
- inline false
- status open
- \begin_layout Plain Layout
- const a = 5
- \end_layout
- \begin_layout Plain Layout
- const b = Vector2(20,20)
- \end_layout
- \begin_layout Plain Layout
- const c = 10+20 # constant expression
- \end_layout
- \begin_layout Plain Layout
- const d = Vector2(20,30).x # constant expression: 20
- \end_layout
- \begin_layout Plain Layout
- const e = [1,2,3,4][0] # constant expression: 1
- \end_layout
- \begin_layout Plain Layout
- const f = sin(20) # sin() can be used in constant expression
- \end_layout
- \begin_layout Plain Layout
- const g = x+20 # invalid, not a constant expression!
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \end_inset
- \end_layout
- \begin_layout Subsection
- Functions
- \end_layout
- \begin_layout Standard
- Functions always belong to a class.
- The scope priority for variable look-up is: local -> class member -> global.
-
- \begin_inset Quotes eld
- \end_inset
- self
- \begin_inset Quotes erd
- \end_inset
- is provided as an option for accessing class members but is not required
- always (and must
- \emph on
- not
- \emph default
- be defined as first parameter, like in Python).
- For performance reasons, functions are not considered class members, so
- they can't be referenced directly.
- A function can return at any point.
- The default return value is null.
- \end_layout
- \begin_layout Standard
- \begin_inset listings
- inline false
- status open
- \begin_layout Plain Layout
- func myfunction(a,b):
- \end_layout
- \begin_layout Plain Layout
- print(a)
- \end_layout
- \begin_layout Plain Layout
- print(b)
- \end_layout
- \begin_layout Plain Layout
- return a+b # return is optional, otherwise null is returned
- \end_layout
- \end_inset
- \end_layout
- \begin_layout Subsubsection
- Statements and Control Flow
- \end_layout
- \begin_layout Standard
- Statements are standard, and can be assignments, function calls, control
- flow structures, etc (see below).
-
- \begin_inset Quotes eld
- \end_inset
- ;
- \begin_inset Quotes erd
- \end_inset
- as separator is entirely optional.
- \end_layout
- \begin_layout Subsubsection
- if/else/elif
- \end_layout
- \begin_layout Standard
- Simple conditions are created by using the
- \emph on
- if/else/elif
- \emph default
- syntax.
- Parenthesis around statements is allowed but not requiered.
- Given the nature of the tab-based indentation, elif can be used instead
- of else:/if: to mantain a level of indentation.
- \end_layout
- \begin_layout Standard
- \begin_inset listings
- inline false
- status open
- \begin_layout Plain Layout
- if [expression]:
- \end_layout
- \begin_layout Plain Layout
- statement(s)
- \end_layout
- \begin_layout Plain Layout
- elif [expression]:
- \end_layout
- \begin_layout Plain Layout
- statement(s)
- \end_layout
- \begin_layout Plain Layout
- else:
- \end_layout
- \begin_layout Plain Layout
- statement(s)
- \end_layout
- \end_inset
- \end_layout
- \begin_layout Subsubsection
- while
- \end_layout
- \begin_layout Standard
- Simple loops are created by using
- \emph on
- while
- \emph default
- syntax.
- Loops can be broken using
- \emph on
- break
- \emph default
- , or continued using
- \emph on
- continue
- \emph default
- :
- \end_layout
- \begin_layout Standard
- \begin_inset listings
- inline false
- status open
- \begin_layout Plain Layout
- while [expression]:
- \end_layout
- \begin_layout Plain Layout
- statement(s)
- \end_layout
- \end_inset
- \end_layout
- \begin_layout Subsubsection
- for
- \end_layout
- \begin_layout Standard
- To iterate a range, array or table a
- \emph on
- for
- \emph default
- loop is used.
- For loops store the index in the loop variable on each iteration.
- \end_layout
- \begin_layout Standard
- \begin_inset listings
- inline false
- status open
- \begin_layout Plain Layout
- for i in [0,1,2]:
- \end_layout
- \begin_layout Plain Layout
- statement # loop iterates 3 times, i being 0,1 and 2
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- var dict = {"a":0, "b":1, "c": 2}
- \end_layout
- \begin_layout Plain Layout
- for i in dict:
- \end_layout
- \begin_layout Plain Layout
- print(dict[i]) # loop iterates the keys, i being "a","b" and c".
- It prints 0, 1 and 2.
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- for i in range(3):
- \end_layout
- \begin_layout Plain Layout
- statement # similar to [0,1,2] but does not allocate an array
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- for i in range(1,3):
- \end_layout
- \begin_layout Plain Layout
- statement # similar to [1,2] but does not allocate an array
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- for i in range(2,8,2):
- \end_layout
- \begin_layout Plain Layout
- statement # similar to [2,4,6] but does not allocate an array
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \end_inset
- \end_layout
- \begin_layout Section
- Classes
- \end_layout
- \begin_layout Standard
- By default, the body of a script file is an unnamed class, and it can only
- be referenced externally as a resource or file.
- Class syntax is meant to be very compact and can only contain member variables
- or functions.
- Static functions are allowed, but not static members (in the spirit of
- thread safety, since scripts can be initialized in separate threads without
- the user knowing).
- In the same way, member variables (including arrays and dictionaries) are
- initialized every time an instance is created.
-
- \end_layout
- \begin_layout Subsection
- Class File Example
- \end_layout
- \begin_layout Standard
- Example of a class file, imagine it being stored in a file like myclass.gd.
- \end_layout
- \begin_layout Standard
- \begin_inset listings
- inline false
- status open
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- var a=5
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- function print_value_of_a():
- \end_layout
- \begin_layout Plain Layout
- print(a)
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \end_inset
- \end_layout
- \begin_layout Subsection
- Inheritance
- \end_layout
- \begin_layout Standard
- A class-file can inherit from a global class, another file or a subclass
- inside another file.
- Multiple inheritance is not allowed.
- The
- \begin_inset Quotes eld
- \end_inset
- extends
- \begin_inset Quotes erd
- \end_inset
- syntax is used:
- \end_layout
- \begin_layout Standard
- \begin_inset listings
- inline false
- status open
- \begin_layout Plain Layout
- # extend from some class (global)
- \end_layout
- \begin_layout Plain Layout
- extends SomeClass
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- # optionally, extend from another file
- \end_layout
- \begin_layout Plain Layout
- extends "somefile.gd"
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- # extend from a subclass in another file
- \end_layout
- \begin_layout Plain Layout
- extends "somefile.gd".Subclass
- \end_layout
- \end_inset
- \end_layout
- \begin_layout Subsection
- Inheritance Testing
- \end_layout
- \begin_layout Standard
- It is possible to check if an instance inherits from a given class.
- For this the
- \begin_inset Quotes eld
- \end_inset
- extends
- \begin_inset Quotes erd
- \end_inset
- keyword can be used as an operator instead:
- \end_layout
- \begin_layout Standard
- \begin_inset listings
- inline false
- status open
- \begin_layout Plain Layout
- static var enemy_class = preload("enemy.gd") # cache the enemy class
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- [..]
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- if ( entity extends enemy_class ):
- \end_layout
- \begin_layout Plain Layout
- entity.apply_damage()
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \end_inset
- \end_layout
- \begin_layout Subsection
- Constructor
- \end_layout
- \begin_layout Standard
- A class can have an optional constructor, a function named
- \begin_inset Quotes eld
- \end_inset
- _init
- \begin_inset Quotes erd
- \end_inset
- that is called when the class is instanced.
- \end_layout
- \begin_layout Subsection
- Sub Classes
- \end_layout
- \begin_layout Standard
- A class file can have subclasses.
- Syntax should be straightforward:
- \end_layout
- \begin_layout Standard
- \begin_inset listings
- inline false
- status open
- \begin_layout Plain Layout
- class SomeSubClass:
- \end_layout
- \begin_layout Plain Layout
- var a=5
- \end_layout
- \begin_layout Plain Layout
- function print_value_of_a():
- \end_layout
- \begin_layout Plain Layout
- print(a)
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- function _init():
- \end_layout
- \begin_layout Plain Layout
- var sc = SomeSubClass.new() #instance by calling built-in new
- \end_layout
- \begin_layout Plain Layout
- sc.print_value_of_a()
- \end_layout
- \end_inset
- \end_layout
- \begin_layout Subsection
- Classes as Objects
- \end_layout
- \begin_layout Standard
- It may be desired at some point to load a class from a file and then instance
- it.
- Since the global scope does not exist, classes must be loaded as a resource.
- Instancing is done by calling the
- \begin_inset Quotes eld
- \end_inset
- new
- \begin_inset Quotes erd
- \end_inset
- function in a class object:
- \end_layout
- \begin_layout Standard
- \begin_inset listings
- inline false
- status open
- \begin_layout Plain Layout
- #load the class (loaded every time the script is instanced)
- \end_layout
- \begin_layout Plain Layout
- var MyClass = load("myclass.gd")
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- #alternatively, using the preload() function preloads the class at compile
- time
- \end_layout
- \begin_layout Plain Layout
- var MyClass2 = preload("myclass.gd")
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- function _init():
- \end_layout
- \begin_layout Plain Layout
- var a = MyClass.new()
- \end_layout
- \begin_layout Plain Layout
- a.somefunction()
- \end_layout
- \end_inset
- \end_layout
- \begin_layout Subsection
- Exports
- \end_layout
- \begin_layout Standard
- Class members can be exported.
- This means their value gets saved along with a scene.
- If class members have initializers to constant expressions, they will be
- available for editing in the property editor.
- Exporting is done by using the export keyword:
- \end_layout
- \begin_layout Standard
- \begin_inset listings
- inline false
- status open
- \begin_layout Plain Layout
- extends Button
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- export var data # value will be saved
- \end_layout
- \begin_layout Plain Layout
- export var number=5 # also available to the property editor
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \end_inset
- \end_layout
- \begin_layout Standard
- One of the fundamental benefits of exporting member variables is to have
- them visible in the property editor.
- This way artists and game designers can modify values that later influence
- how the program runs.
- For this, a special export syntax is provided for more detail in the exported
- variables:
- \end_layout
- \begin_layout Standard
- \begin_inset listings
- inline false
- status open
- \begin_layout Plain Layout
- #if the exported value assigns a constant or constant expression, the type
- will be infered and used in the editor
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- export var number=5
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- #export can take a basic datatype as argument, which will be used in the
- editor
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- export(int) var number
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- #export can also take a resource type as hint
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- export(Texture) var character_face
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- #integers and strings hint enumerated values
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- export(int,"Warrior","Magician","Thief") var character_class # (editor will
- set them as 0,1 and 2)
- \end_layout
- \begin_layout Plain Layout
- export(String,"Rebecca","Mary","Leah") var character_name
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- #strings as paths
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- export(String,FILE) var f # string is a path to a file
- \end_layout
- \begin_layout Plain Layout
- export(String,DIR) var f # string is a path to a directory
- \end_layout
- \begin_layout Plain Layout
- export(String,FILE,"*.txt") var f # string is a path to a file, custom filter
- provided as hint
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- #integers and floats hint ranges
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- export(int,20) var i # 0 to 20 allowed
- \end_layout
- \begin_layout Plain Layout
- export(int,-10,20) var j # -10 to 20 allowed
- \end_layout
- \begin_layout Plain Layout
- export(float,-10,20,0.2) var k # -10 to 20 allowed, with stepping of 0.2
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- #color can hint availability of alpha
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- export(Color,RGB) var col # Color is RGB
- \end_layout
- \begin_layout Plain Layout
- export(Color,RGBA) var col # Color is RGBA
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \end_inset
- \end_layout
- \begin_layout Standard
- It must be noted that even if the script is not being run while at the editor,
- the exported properties are still editable (see below for
- \begin_inset Quotes eld
- \end_inset
- tool
- \begin_inset Quotes erd
- \end_inset
- ).
- \end_layout
- \begin_layout Subsection
- Static Functions
- \end_layout
- \begin_layout Standard
- A function can be declared static.
- When static, it has no access to the instance member variables or
- \begin_inset Quotes eld
- \end_inset
- self
- \begin_inset Quotes erd
- \end_inset
- .
- This is mainly useful to make libraries of helper functions:
- \end_layout
- \begin_layout Standard
- \begin_inset listings
- inline false
- status open
- \begin_layout Plain Layout
- static func sum2(a,b):
- \end_layout
- \begin_layout Plain Layout
- return a+b
- \end_layout
- \end_inset
- \end_layout
- \begin_layout Subsection
- Asserting
- \end_layout
- \begin_layout Standard
- It is possible to assert a condition, which will cause a debugger break
- if false.
- Just use the built-in 'assert' function.
- \end_layout
- \begin_layout Standard
- \begin_inset listings
- inline false
- status open
- \begin_layout Plain Layout
- assert(a==2)
- \end_layout
- \begin_layout Plain Layout
- # if a is not 2, it will generate a debugger break
- \end_layout
- \end_inset
- \end_layout
- \begin_layout Subsection
- Tool Mode
- \end_layout
- \begin_layout Standard
- Scripts by default don't run inside the editor, and only the exported properties
- can be changed.
- In some cases it is desired that they do (as long as they don't execute
- game code or manually avoid doing so).
- For this, the
- \begin_inset Quotes eld
- \end_inset
- tool
- \begin_inset Quotes erd
- \end_inset
- keyword exists, and must be placed at the top of the file:
- \end_layout
- \begin_layout Standard
- \begin_inset listings
- inline false
- status open
- \begin_layout Plain Layout
- tool
- \end_layout
- \begin_layout Plain Layout
- extends Button
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- func _init():
- \end_layout
- \begin_layout Plain Layout
- print("Hello")
- \end_layout
- \end_inset
- \end_layout
- \begin_layout Subsection
- Memory Management
- \end_layout
- \begin_layout Standard
- If a class inherits from
- \emph on
- Reference
- \emph default
- , then instances will be freed when no longer in use.
- No garbage collector exists, just simple reference counting.
- By default, all classes that don't define inheritance extend
- \emph on
- Reference
- \emph default
- .
- If this is not desired, then a class must inherit
- \emph on
- Object
- \emph default
- manually and must call instance.free().
- To avoid reference cycles that can't be freed, a weakref() function is
- provided for creating weak references.
-
- \end_layout
- \begin_layout Subsection
- Function References
- \end_layout
- \begin_layout Standard
- Functions can't be referenced because they are not treated as class members.
- There are two alternatives to this, though.
- The
- \begin_inset Quotes eld
- \end_inset
- call
- \begin_inset Quotes erd
- \end_inset
- function or the funcref() helper.
- \end_layout
- \begin_layout Standard
- \begin_inset listings
- inline false
- status open
- \begin_layout Plain Layout
- instance.call("funcname",args) # call a function by bane
- \end_layout
- \begin_layout Plain Layout
- \end_layout
- \begin_layout Plain Layout
- var fr = funcref(instance,"funcname") #create a function ref
- \end_layout
- \begin_layout Plain Layout
- fr.exec(args)
- \end_layout
- \end_inset
- \end_layout
- \end_body
- \end_document
|