CSE 380 – Computer Game Programming Scripting and Lua Lua.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
Lecture-5 Though SQL is the natural language of the DBA, it suffers from various inherent disadvantages, when used as a conventional programming language.
VBA Modules, Functions, Variables, and Constants
Case, Arrays, and Structures. Summary Slide  Case Structure –Select Case - Numeric Value Example 1 –Select Case - String Value Example  Arrays –Declaring.
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
Program Design and Development
Guide To UNIX Using Linux Third Edition
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
1 CS101 Introduction to Computing Lecture 29 Functions & Variable Scope (Web Development Lecture 10)
Day 4 Objectives Constructors Wrapper Classes Operators Java Control Statements Practice the language.
OOP Languages: Java vs C++
References: 1. “Programming in LUA, 2 nd ed.”, Roberto Lerusalmschy Chapters “Lua Reference Manual” (included in Lua installation or online)
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
Computer Science 111 Fundamentals of Programming I Overview of Programming.
Introduction to Java University of Sunderland CSE301 Harry R. Erwin, PhD.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
1 Session 3: Flow Control & Functions iNET Academy Open Source Web Programming.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
Games Development 2 Lua Scripting CO3301 Week 6. Contents Introducing Lua –Comparison with Python Lua Language Overview Interfacing Lua with C++
Chapter 8: Arrays and Functions Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
Chapter 10: BASH Shell Scripting Fun with fi. In this chapter … Control structures File descriptors Variables.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
Holistic Mobile Game Development with Unity 2015 Taylor & Francis. All rights Reserved.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
I Power Higher Computing Software Development High Level Language Constructs.
JavaScript, Fourth Edition
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
CSCI 171 Presentation 6 Functions and Variable Scope.
RUBY by Ryan Chase.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
Functions Illustration of: Pass by value, reference Scope Allocation Reference: See your CS115/215 textbook.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
EEL 3801 C++ as an Enhancement of C. EEL 3801 – Lotzi Bölöni Comments  Can be done with // at the start of the commented line.  The end-of-line terminates.
MIT-AITI: Functions Defining and Invoking Functions Functions as Data Function Scope: The call Object Function Arguments: The arguments objects Function.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
PHP Reusing Code and Writing Functions 1. Function = a self-contained module of code that: Declares a calling interface – prototype! Performs some task.
Ada, Scheme, R Emory Wingard. Ada History Department of Defense in search of high level language around Requirements drafted for the language.
Procedure Definitions and Semantics Procedures support control abstraction in programming languages. In most programming languages, a procedure is defined.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
INTRODUCTION BEGINNING C#. C# AND THE.NET RUNTIME AND LIBRARIES The C# compiler compiles and convert C# programs. NET Common Language Runtime (CLR) executes.
Web Database Programming Using PHP
Chapter 9: Value-Returning Functions
Web Database Programming Using PHP
CS 326 Programming Languages, Concepts and Implementation
Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. It was created by Guido van Rossum during.
Introduction to Python
Introduction to the C Language
What Is a Program? A program is like an algorithm, but describes a process that is ready or can be made ready to run on a real computer Retrieved from:
Substitution in string value
Introduction to Python
Lecture 2 Python Programming & Data Types
Functions A function is a “pre-packaged” block of code written to perform a well-defined task Why? Code sharing and reusability Reduces errors Write and.
Lecture 2 Python Programming & Data Types
Catharine West Bo Aye Saljin LaRocca references
Predefined Functions Revisited
PHP an introduction.
The Lua Chunk Vault, an enhancement to epics base
Introduction to Python
SPL – PS1 Introduction to C++.
Python fundamental.
Presentation transcript:

CSE 380 – Computer Game Programming Scripting and Lua Lua

What is a scripting language? A higher-level programming language (of sorts) Interpreted by another program at runtime –like a game engine Hardware Machine Code Assembly Code High-Level Language Code Scripting Language Code

The first one? SCUMM Script Creation Utility for Maniac Mansion –by LucasArts for Commodore 64

What’s the point? NO MORE CONSTANTS –Why? –What’s wrong with constants? They’re simpler languages –So? –Doesn’t more languages mean more complexity? Programming for non-programmers Compiler-time liberated development Tools + Scriping

And for games? Make Mods or Original Games Use scripts to specify: –Game Settings –GUI layout –Audio cues –Control bots –Responses to game events Bottom Line: –leave the heavy lifting to the engine. How? tap into engine via premade script functions & data

2 Scripting Flavors Data definition languages –declarative statements –used at game or level load time Runtime languages –code executes within engine context at runtime –extend or customize engine –allows for more complex instructions worldWidth:800 function process act(act) for i, act in ipairs(act) do if act:is_alive() then act.process() end

Typical Properties of Game Scripting Languages Interpreted Lightweight Support for rapid iteration Convenience/Ease of use Good for Rapid Prototyping

Popular Game Scripting Languages Game Engine –QuakeC –UnrealScript General Purpose –python –Lua

A crash course in Lua Let’s learn some simple stuff –Commenting –Variables –Operators –Functions –Tables –Conditional Statements –Iteration Download LuaExample.zip and open Ref:

A note about Lua Lua is a C library Using it in a C++ program can be tricky –structs instead of objects –global methods –unsupported C functions An alternative is LuaPlus –not standard Lua –you could write your own wrapper classes as well

Lua Commenting For single line, start line with “--” –Ex: -- THIS IS A COMMENT To span multiple lines: –open with --[[ –close with ]]-- –Ex: --[[ THIS IS A COMMENT --]]

Lua Variables Dynamically typed. Huh? –they can change type x = 3-- x is an integer x = x is a float x = "PI"-- x is a String A Lua variable can be a: –number, string, boolean, table, function, nil, userdata, or thread –nil ≈ NULL also marks variable for deletion Default scope for Lua variables is global

Lua Operators Many the regular suspects –like +, -, *, /, %, =, ==,, = Some you may not have used before, like: ^ for exponentiation ~= for testing for inequality.. for string concatenation And some are missing –like ++, --, +=, -=, *=, /= And some are done via keywords –Like and, or, and not

Lua Functions First class objects. Huh? –Can be treated like any other variable passed as a method argument assigned to a variable Function Declaration Example: function Square(val) return val * val end Function Invocation Example: x = Square(5)-- invoke our function print(x)-- prints 25

Lua Tables Lua’s only data structure Arrays and generic dictionaries all in one. Ex: prime = {2, 3, 5, 7, 11 } -- make a table print(prime[2]) -- access an element, print 5 prime[2] = assign a value Tables can be indexed by other types. Ex: idTable = {}-- make a table idTable["id1"] = put a num in idTable["id2"] = and another Table is actually either an array or a map

Lua Conditionals Support for if … elseif … else Ex: if x == 5 then print(5) elseif x == 6 then print(5) print(6) else print(0) end How does it know when one code block ends and another begins?

Lua Iteration Support for while and for statements Ex: prime = {2, 3, 5, 7, 11} for index, value in ipairs(prime) do print(index, value) end Nested Example: for i = 1, 10, 1 do if (i % 2) == 2 then print(i) end

C++  Lua and Lua  C++ We may need to do both Tricky with C++. Why? –Lua is in C. Solution: Use LuaPlus –C++ library for interfacing with Lua –Not Lua standard Wed: –LuaPlus hands on examples –C++  LuaPlus –LuaPlus  C++ –How and why to do so

Reference Game Engine Architecture by Jason Gregory –Chapter 14: Runtime Gameplay Foundation Systems Game Coding Complete, 4 th Edition by Mike McShaffry and David Graham –Chapter 12: Scripting with Lua