Programming
What does “scope” mean?
The scope of a variable is the part of a script that defines the variable and in which it can be referenced. There are two main types of scope: global and local.
Global Scope
The global scope is all of the script that is not inside a function, if statement, or other conditional structure. Code from anywhere in the script can access global variables. There is only one global scope.
Local Scope
Code that is inside a function or in any local block (one that is inset by four spaces) defines a local scope. Only code that is in the same local scope can access a local variable. There can be many local scopes.
Is Lipi Script an Object-Oriented Language?
Although Lipi Script is not strictly an object-oriented programming language, it includes certain object-oriented characteristics, such as user-defined types (UDTs). Scripts can create objects as instances of a UDT. These objects consist of one or more fields that can store values of various data types.
Here is a simple example of using the type
keyword to create an object:
indicator("Object demo")
// Define a new type named `pivot`.
type pivot {
int x
float y
bool isHigh
}
// Create a new `pivot` with specific values.
pivot newPivot = pivot.new(bar_index, close, true)
// Plot the `y` component of `newPivot`.
plot(newPivot.y)
In this example, we create an object newPivot
, which is an instance of the user-defined type pivot
. The script then plots the y
field of newPivot
.