Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Getting Started

Hud.setlabel text question  [SOLVED]

You feel lost? You don't understand how to use ShiVa?

Hud.setlabel text question

Postby 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?
User avatar
straybullet
Expert Boarder
Expert Boarder
 
Posts: 112

Re: Hud.setlabel text question

Postby 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.
http://cur.lv/1x0wx via an ad! Thanks
User avatar
shivachristy
Platinum Boarder
Platinum Boarder
 
Posts: 1038
Location: UK

Re: Hud.setlabel text question

Postby 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.
User avatar
straybullet
Expert Boarder
Expert Boarder
 
Posts: 112

Re: Hud.setlabel text question  [SOLVED]

Postby 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
http://cur.lv/1x0wx via an ad! Thanks
User avatar
shivachristy
Platinum Boarder
Platinum Boarder
 
Posts: 1038
Location: UK

Re: Hud.setlabel text question

Postby shivachristy » 29 Feb 2012, 19:26

check your case sensitivity label or Label
http://cur.lv/1x0wx via an ad! Thanks
User avatar
shivachristy
Platinum Boarder
Platinum Boarder
 
Posts: 1038
Location: UK

Re: Hud.setlabel text question

Postby 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.
Last edited by neilb on 29 Feb 2012, 22:28, edited 1 time in total.
neilb
Platinum Boarder
Platinum Boarder
 
Posts: 463
Location: Adelaide, South Australia

Re: Hud.setlabel text question

Postby 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.
User avatar
straybullet
Expert Boarder
Expert Boarder
 
Posts: 112


Return to Getting Started