Javascript for Begginers - Construct 3

4

Index

Stats

4,378 visits, 8,219 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 5 Sep, 2021. Last updated 7 Sep, 2021

Working With Texts

Change the colour of text to red , ( must be white initialy to work )

	textA = runtime.objects.A.getFirstInstance();
	textA.colorRgb = [1,0,0];

Now lets show some text from sprite.x that output the x position from the sprite

Dont forget to convert the variable to a string ( in this case n variable )

function Tick(runtime)
{
const player = runtime.objects.Sprite.getFirstInstance();
var abc = player.x
var n = abc.toString();
var textA = runtime.objects.A.getFirstInstance();
textA.text = n
}

Another Example of Normal usage of Text

const player = runtime.objects.Sprite.getFirstInstance();
var ab = "?"

const textA = runtime.objects.A.getFirstInstance();
textA.text = "Hello" + " How are you  " + ab
//output : Hello How are you ?

In the example bellow I create a txt file and imported it into project folder , I named the file to "myfile.txt" and I wrote in it " Hello World " , and it will be displayed in the text object

async function OnBeforeProjectStart(runtime)

{
	
	const textFileUrl = await runtime.assets.getProjectFileUrl("myfile.txt");
	const myTxt = runtime.objects.Text.getFirstInstance();
	const response = await fetch(textFileUrl);
	const fetchedText = await response.text();
	
myTxt.text = fetchedText
	
	runtime.addEventListener("tick", () => Tick(runtime));
}
  • 1 Comments

  • Order by
Want to leave a comment? Login or Register an account!