Text separation help

I am trying to create a Text Adventure game, but i am having problems trying to have both the title for the game and the game text display at the same time. Is there a way to create different text, so that i can have Story be a variable that displays near the center of the screen, while still having custom background colors, and a seperate Title variable that displays at the top of the screen?

//Setup
{
	//Main Canvas Setup
	{
	function setup()
	{
		createCanvas(600,600);
		background(0);
		input = createInput();
		input.position(210,500);
		input.size(200);
		button = createButton('submit');
		button.position(430,501);
	}
}
	//Text Control and Game Coloring
	{
		function draw()
		{
			fill(190);
			rect(-1,-1,600,50);
			fill(150);
			rect(-1,50,600,600);
			textAlign(CENTER);
			drawWords(width * 0.5);
		}
	}
	//Story Text
	{
		function drawWords(x)
		{
			textSize(35);
			fill(0);
			text(Story, x, 300);
		}
	}
	//Game Title Text
	{
		function drawWords(x)
		{
			textSize(45);
			fill(0);
			text(Title, x, 36);
		}
	}
}
1 Like

Yes.

You got 2 functions of the same name, change 1 name and call both from draw()

Get rid of the additional { } brackets

2 Likes

so should i just change one of them to
function drawWords(y) ?
and yeah, im using the extra {} brackets to help group different sections of the code together so its easier for me to find things while editing the code.

1 Like

Yes

like this maybe?



//Setup
function setup() {
  createCanvas(600, 600);
  background(0);
  input = createInput();
  input.position(210, 500);
  input.size(200);
  button = createButton('submit');
  button.position(430, 501);
} // setup

// Main function
function draw() {
  fill(190);
  rect(-1, -1, 600, 50);
  fill(150);
  rect(-1, 50, 600, 600);
  textAlign(CENTER);
  drawStory(width * 0.5);
  // what comes here ?
}

//Story Text
function drawStory(x) {
  textSize(35);
  fill(0);
  text(Story, x, 300);
}

//Game Title Text
function drawTitle(x) {
  textSize(45);
  fill(0);
  text(Title, x, 36);
}
2 Likes

Well… yeah…

imho:
in this case exactly this stopped processing from showing a proper error message (duplicate function name not allowed) and stopped you from being able to work further on it

But problem solved! :wink:

1 Like

well, thanks for the help

1 Like

you wouldnt believe how hard it was for me to find this forum btw… for some reason its seperate from the community section of the processing website

1 Like

I see! Weird!

I am very sorry to hear that!

I am glad you found it.

Warm regards,

Chrisir

1 Like

Sorry to hear that. If you are trying to find it again, some techniques that may help:

1 Like