Page Functions
The page fn
specifier is used to declare a function that is the entrypoint
when a user navigates to a particular page in the game.
Of all the pages, the most important is the HomePage
, which is normally the first function
that runs in an Easel program.
pub page fn World.HomePage() {
Landing {
// Calling AboutPage creates an `intent` to navigate to the About page,
// but the button must be clicked to invoke the intent
Button(AboutPage, tier=Color:Secondary, width=25) { "About" }
}
}
pub page fn World.AboutPage() {
Content {
P { "This is the about page." }
}
}
Declaring a page function
Declare a page function using the page fn
specifier.
Every page must have a unique name, even if it is private,
as the page name is used to uniquely identify the page in the URL.
The page fn HomePage
will be the first function that runs in an Easel program
when people visit your game.
A page
function can take any number of parameters, but they must all be strings.
This is because the page is hosted at a particular URL which is a string,
and the parameters are passed in the URL.
All parameters will be converted to strings when calling a page
function.
Navigating to another page
Calling a page
function does not actually navigate to the page,
nor does it execute any statements in the body of the page
function.
Instead, it returns an intent
to navigate to that page with the given parameters.
This intent
can be attached to a Button
.
When the button is clicked, the intent will cause the user's browser to navigate to the page.