Author Topic: TextSetText is not working for me!  (Read 1660 times)

PlatinumLine

  • Guest
TextSetText is not working for me!
« on: January 11, 2014, 07:48:40 pm »
Ok, ive been out of the programming loop for a few years now, but decided  to try to write a small app for my work. I am just playing around with the basic features right now just to get a feel for it.
I basically took the ball app and slightly modified it.
I added a button to the screen, Im trying to get it to print out the amount of times you click the button. I can do this with TextAdd(), but all that does is write over the same text over and over. So I am trying TextSetText() and it is not doing anything. Basically its saying
TextSetText - text does not exist:  Yep you got 1
TextSetText - text does not exist:  Yep you got 2
TextSetText - text does not exist:  Yep you got 3
TextSetText - text does not exist:  Yep you got 4
TextSetText - text does not exist:  Yep you got 5
TextSetText - text does not exist:  Yep you got 6
TextSetText - text does not exist:  Yep you got 7

when i try to take that same exact "int text3" and just TextSetxy(), it will move it whereever I want...but it for some reason will not update the text...here is the code.


#include "DragonFireSDK.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

//===============================================
int Ballx;
int Bally;
int BallImage;
int BallView;
int vw;
int bt;
int tx;
int ft;
int count = 0;
int times = 0;
char msg[200];
int font;
char *text = "yep, you got ";
int try1 = 0;
char text2[20];
int move = 50;
int text3;



//===============================================
int OnButton(int id)
{
   
   id++;
   printf("hi there");
   Bally = 80;
   
    sprintf(text2, " Yep you got %d", count);
   
   if (count >= 1)
   {
      TextSetText(text3, text2);
   }
    count++;
   return(id);
}
void AppMain()
{
   
   font = FontAdd("FontMedium");
   vw=ViewAdd("Background.png",0,0); // create a view and load an image at specified x,y
   bt = ButtonAdd("PLineButton", 20, 20, OnButton, 1);
    text3 = TextAdd(50, 80, "adsjjeje", font);
      
   Ballx=120;
   Bally=80;

   BallImage=ImageAdd("Ball.png"); // load an image
   BallView=ViewAdd(BallImage,Ballx,Bally); // show the image on the screen
   OnButton(times);
   
}

//===============================================
void OnTimer()
{
   
   Bally+=2;
   ViewSetxy(BallView,Ballx,Bally); // modify the x,y position of the view
   
   
}

PlatinumLine

  • Guest
Re: TextSetText is not working for me!
« Reply #1 on: January 11, 2014, 07:58:45 pm »
and actually, when I use this code instead, using the same "text3", it will move the text across the screen as you hit the button, but still will not update the text.

int OnButton(int id)
{
   
   id++;
   Bally = 80;
   
    sprintf(text2, " Yep you got %d", count);
   
   if (count >= 1)
   {
      TextSetText(text3, text2);
      TextSetxy(text3, move++, 80);
   }
    count++;
   return(id);
}

expleo

  • Jr. Member
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
Re: TextSetText is not working for me!
« Reply #2 on: January 20, 2014, 04:26:52 am »
Hello, just browsing your code:

TextSetText(text3, text2);

With this line, you say you want the content of variable text2 into the variable text3.

You have though defined text 3 as a text object, not the actual text:

text3 = TextAdd(50, 80, "adsjjeje", font);

What you want is:

declarations:

int myNumberofClicks;  // your counter for number of clicks
char text_myNumberofClicks[10]; // this will be used to transform the INT variable myNumber into a char that can be printed
int myTextObject; //the text instance you want to use.

main:

myTextObject=TextAdd(50,80,"           ",font); //we leave some blanks so we dont get a buffer issue

and on the onbutton:

sprintf (text_myNumberofClicks,"%d",myNumberofClicks); // here we put the integer value from count into char that can be printed
TextSetText(myTextObject,text_myNumberofClicks); // here we put the now 'casted' value from count to the char variable myNumberofClicks, and put it to be displayer by the text object  'myTextObject'.



There are 2 things we can learn from this:

1- to print integer values, you need to typecast them into char (use sprintf)

and

2- learn what is a variable, and what is an object. You will come across similar issues later, where you have an int IMAGE, and then an int IMAGEVIEW. The imageview shows the image, but the variable IMAGE holds 'what' image to show.

I didnt test the code I wrote there, so might be some errors, let me know if I fail to explain well enough how to solve it :)
« Last Edit: January 20, 2014, 04:30:55 am by expleo »