ShiVa3D
Hud.setlabel text question [SOLVED]
You feel lost? You don't understand how to use ShiVa?Hud.setlabel text question
by straybullet » 29 Feb 2012, 18:08
I have copied the iphone controller hud & code to my game. It all works fine
In the hud editor I added a new component named thescore and gave it a default label.
In my mainai inside onit I have the following from the iphonecontroller code
hud.newTemplateInstance ( this.getUser ( ), "iPhoneJoypadEmulation2", "iPhoneJoypadEmulation" )
Then I have an on collision begin event in one of my objects that needs to update this label (it updates the label with the score)
So in the objects AI I have a number variable named thescorecount which I increase by 1 every time the oncollisionbegin event is fired
So I am trying the following code to update the label which is called thescore with the value from thescorecount
local hUser = application.getCurrentUser ( )
local hComponent = hud.getComponent ( hUser, "iPhoneJoypadEmulation.thescore" )
hud.setLabelText ( hComponent ,this.thescorecount ( ) )
When the collision event fires and runs this code an error occurs..
[+ Warning ] {Scripting } [Internal] : Function 'setLabelText'
I have also tried using local hComponent = hud.getComponent ( hUser, "iPhoneJoypadEmulation2.thescore" )
What am I missing?
In the hud editor I added a new component named thescore and gave it a default label.
In my mainai inside onit I have the following from the iphonecontroller code
hud.newTemplateInstance ( this.getUser ( ), "iPhoneJoypadEmulation2", "iPhoneJoypadEmulation" )
Then I have an on collision begin event in one of my objects that needs to update this label (it updates the label with the score)
So in the objects AI I have a number variable named thescorecount which I increase by 1 every time the oncollisionbegin event is fired
So I am trying the following code to update the label which is called thescore with the value from thescorecount
local hUser = application.getCurrentUser ( )
local hComponent = hud.getComponent ( hUser, "iPhoneJoypadEmulation.thescore" )
hud.setLabelText ( hComponent ,this.thescorecount ( ) )
When the collision event fires and runs this code an error occurs..
[+ Warning ] {Scripting } [Internal] : Function 'setLabelText'
I have also tried using local hComponent = hud.getComponent ( hUser, "iPhoneJoypadEmulation2.thescore" )
What am I missing?
-

straybullet - Expert Boarder

- Posts: 115
Re: Hud.setlabel text question
by shivachristy » 29 Feb 2012, 18:17
try
hud.newTemplateInstance ( this.getUser ( ), "iPhoneJoypadEmulation2", "iPhoneJoypadEmulationQQ" )
or whichever one is the instance add QQ or something.
I think
iPhoneJoypadEmulation2
and iPhoneJoypadEmulation
are huds in there own right.
hope this helps.
hud.newTemplateInstance ( this.getUser ( ), "iPhoneJoypadEmulation2", "iPhoneJoypadEmulationQQ" )
or whichever one is the instance add QQ or something.
I think
iPhoneJoypadEmulation2
and iPhoneJoypadEmulation
are huds in there own right.
hope this helps.
-

shivachristy - Platinum Boarder

- Posts: 959
- Location: UK
Re: Hud.setlabel text question
by straybullet » 29 Feb 2012, 18:25
Sorry.. but I am not following what you mean.
All the huds are working, the score is placed inside the existing iphone hud that was the example. The default label for score shows up fine, I just can not update the text of the label.
Why create a new instance when the current hud is showing?
I apologize, it just seems odd to me its right there in front of my face and all I want to do is change the text.
All the huds are working, the score is placed inside the existing iphone hud that was the example. The default label for score shows up fine, I just can not update the text of the label.
Why create a new instance when the current hud is showing?
I apologize, it just seems odd to me its right there in front of my face and all I want to do is change the text.
-

straybullet - Expert Boarder

- Posts: 115
Re: Hud.setlabel text question [SOLVED]
by shivachristy » 29 Feb 2012, 19:23
oninit:
hud.newTemplateInstance ( this.getUser ( ), "iPhoneJoypadEmulation2", "iPhoneJoypadEmulation" )
onFPS
local label = hud.getComponent ( this.getUser ( ), "iPhoneJoypadEmulation.FPSLabel" )
if ( label )
then
hud.setLabelText ( label, "Fps : "..math.roundToNearestInteger ( 1 / application.getAverageFrameTime ( ) ) )
end
this.postEvent ( 1, "onFPS" )--this resends and writes the framerate to my label.onFPS being a handler (this code is in onFPS)
this is working for me,
Ive got to cook supper now.
I hope it helps
hud.newTemplateInstance ( this.getUser ( ), "iPhoneJoypadEmulation2", "iPhoneJoypadEmulation" )
onFPS
local label = hud.getComponent ( this.getUser ( ), "iPhoneJoypadEmulation.FPSLabel" )
if ( label )
then
hud.setLabelText ( label, "Fps : "..math.roundToNearestInteger ( 1 / application.getAverageFrameTime ( ) ) )
end
this.postEvent ( 1, "onFPS" )--this resends and writes the framerate to my label.onFPS being a handler (this code is in onFPS)
this is working for me,
Ive got to cook supper now.
I hope it helps
-

shivachristy - Platinum Boarder

- Posts: 959
- Location: UK
Re: Hud.setlabel text question
by shivachristy » 29 Feb 2012, 19:26
check your case sensitivity label or Label
-

shivachristy - Platinum Boarder

- Posts: 959
- Location: UK
Re: Hud.setlabel text question
by neilb » 29 Feb 2012, 21:29
I think you might be trying to assign a number to the label which wants a string.
““..this.thescorecount()
Putting double quotes ahead of the value is a quick way to convert it.
““..this.thescorecount()
Putting double quotes ahead of the value is a quick way to convert it.
Last edited by neilb on 29 Feb 2012, 22:28, edited 1 time in total.
Re: Hud.setlabel text question
by straybullet » 29 Feb 2012, 22:18
Thank you it was yours and shivachristy's post that got me going. I had to use the "" as you suggested and shivachristy 's code help me understand it a little more.
neilb wrote:I think you might ne trying to assign a number to the label which wants a string.
““..this.thescorecount()
Putting double quotes ahead of the value is a quock way to convert it.
-

straybullet - Expert Boarder

- Posts: 115
7 posts
• Page 1 of 1