350 likes | 372 Views
Learn to create multiplayer apps on the web using scripting events, event triggers, implicit parameters, and flow control constructs. Dive into array and set manipulation for dynamic content.
E N D
SW Development CourseMultiplayer Multimedia Apps on the Web 2 – Scripting Events Language elements Flow control constructs Implicit parameters Movement EVENTs Navigating documentation Array and SETs
EVENT • Whatever happens, an EVENTO triggers • When an EVENT triggers, the system looks for a specific piece of software • At each call, if that piece of software is found, it is executed
EVENT example • At the game’s startup • onStart Event • If code for onStart is found, it is executed
EVENT • EVENT id_evento • Instruction • Instruction .. • End_EVENT verify Developers Ref.
EVENT Example • EVENT onStart • Call PopMonster() ‘My function – make a monster ‘to pop up in a random room • End_EVENT
EVENT example • A character gets looked at (clicked on) • The event person.onLook triggers • If existing, the event gets executed and stop. • Otherwise the generic event onLook triggers • If existing, the event gets executed.
Implicit parameters • $OWNER – who owns the event equals to this in Java • $AGENT – who started the action • $TARGET – third actor (sometimes used, mostly not)
EVENT Model: person.onLook $AGENT $OWNER
onLook EVENT Example SCRIPTS EVENT guy.onLook Speak $OWNER,$AGENT,“So, what’s up?" END_SCRIPTS
Speak • Speak [speaker,][destination,] phrase [, phrase …] • “speaker” Defaults to: $OWNER • “destination” Defaults to: $AGENT • If there are many phrases, they are printed in cycle
Speak from this… SCRIPTS EVENT guy.onLook Speak $OWNER,$AGENT,“So, what’s up?“ END_SCRIPTS
…to this (compact form) SCRIPTS EVENT guy.onLook Speak“So, what’s up?“ END_SCRIPTS
Pre-defined values SYS (System voice) • Use as “speaker” when needed $WORLD (All connected players) • Use as “destination”
onLook EVENT Example SCRIPTS EVENT guy.onLook Speak SYS,$WORLD,“Player “ + $AGENT + “ looks “ + $OWNER END_SCRIPTS
Object Model di CHARACTERS • Use the dot . to refer to an object’s property Person.name Name of the person Person.container Where person is (room object) Person.container.id (room’s ID) Person.container.name (room’s name)
Print • Print [dest,] What [, what…] • Print “In this room there’s some light” • Print “OWNER=“ + $OWNER + “ AGENT= “ + $AGENT + “ TARGET=“ + $TARGET
Assignment – remember a value • Birthday = “July 26th” • Print Birthday July 26th
If .. Else • If (condition) • Istructions • Else • Istructions • End_If • No THEN • End_If and not: “End If”
RndInt(N) • Returns a random nunmber from 1 a N
If .. Else IfRndInt(2) = 1 Print “ODD!” Else Print “EVEN!” End_If
EVENT Model: person.onHear $TARGET $AGENT $OWNER
Printing implicit parameters • Print “OWNER=“ + $OWNER + “ AGENT= “ + $AGENT + “ TARGET=“ + $TARGET
Inspecting the log • System folder • File name is: debug#.log • # = number of slot you used • Note: If it is missing then edit setting debugTo= in the worldnav#.properties file
Echoing speech • EVENT person.onHear • Speak $OWNER,$AGENT,”You said: “ + $TARGET + “, what do you mean?” • END_EVENT
EVENT Model: room.onLoose $AGENT $TARGET $OWNER
EVENT Model: person.onExit $OWNER $AGENT $TARGET
EVENT Model: person.onEnter $OWNER $AGENT $TARGET
EVENT Model: room.onReceive $AGENT (?) $TARGET $OWNER
Navigating Developers Reference • How DimensioneX works • Configuration • Design-time part (DXW) • Run-Time part (SmallBasic) • Objects’ Object Model • System (built-in) Events • Available Functions • Available Istructions
Array arrGreets 1 2 3 4 “ciao” “hola” “hi” “hello”
Array + RndInt(N) • arrGreets = NewSet(“ciao,hola,hello”) • Speak arrGreets(RndInt(3)) • Ciao • Hello • Ciao • Hola
SET setObjects book crown scroll sword
For Each Next • For Each var In set • Instructions • Next • Careful! To set and arrays
For Each Next + SET Print “present characters:” For Eachx In getCharactersIn($WORLD) Printx.name Next
Summary • Events • Language elements • Flow control constructs • Implicit parameters • Movement EVENTs • Navigating documentation • Array and SETs