Thread Tools Display Modes
09-25-14, 01:12 PM   #1
Danielps1
Guest
Posts: n/a
Limit string length

Hi quick question!

I want to manipulate my string-length so it only shows the first numbers infront of a comma/dot.

my code looks like this
Lua Code:
  1. self.moneyText:SetText(GetMoney()/10000,10)

Very simple. But I don't know how to and I couldn't find a solution via google.

thanks^^
  Reply With Quote
09-25-14, 01:19 PM   #2
sirann
A Flamescale Wyrmkin
Join Date: Mar 2007
Posts: 142
So you're basically just trying to show the amount of gold, not silver or copper (the 10000 division)?

couldn't you do
Lua Code:
  1. self.moneyText:SetText(math.floor(GetMoney()/10000))
  Reply With Quote
09-25-14, 01:23 PM   #3
Danielps1
Guest
Posts: n/a
thanks ! exactly what I needed. I just don't know much syntax and didn't know math.floor existed.

the 10 is the fontsize if someone wonders why I put it there.

Lua Code:
  1. self.moneyText:SetText(math.floor(GetMoney()/10000),10)
  Reply With Quote
09-25-14, 01:32 PM   #4
sirann
A Flamescale Wyrmkin
Join Date: Mar 2007
Posts: 142
I dont think that works that way.

You would need to do
Lua Code:
  1. self.moneyText:SetFont('pathtofontfile', size, 'flags')

size is an integer, flags are all caps flags for outlines MONOCHROME OUTLINE THICKOUTLINE

I may be dead wrong, I've just always seen the way I put it done, but then again I break more stuff than I fix so take it with a grain of salt.
  Reply With Quote
09-25-14, 01:38 PM   #5
Danielps1
Guest
Posts: n/a
Yeah I forgot that the previous version was

Lua Code:
  1. GetCoinTextureString(GetMoney(),10)

Which works different
http://www.wowwiki.com/API_GetCoinTextureString
  Reply With Quote
09-25-14, 01:59 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
Originally Posted by sirann View Post
You would need to do
Lua Code:
  1. self.moneyText:SetFont('pathtofontfile', size, 'flags')
If you want to just change the size and nothing else, you can use FontString:SetTextHeight().
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
09-26-14, 12:04 AM   #7
Danielps1
Guest
Posts: n/a
I've noticed another problem. The value doesn't update/doesn't change from 0 if you don't /reload

Is there a way to still make it work?
  Reply With Quote
09-26-14, 01:09 AM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You need to register for the event that fires when you gain or lose money.

If you need help figuring out how to do that, post the rest of your code.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
09-26-14, 01:28 AM   #9
Danielps1
Guest
Posts: n/a
Makes sense,

I don't really know how though. This is the code of TinyMainbar (the Addon I used to make my panels)

http://pastebin.com/pXn6ZtF5
  Reply With Quote
09-26-14, 02:15 AM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The code already does what I describe, but you've broken it by moving the "how much money does the player have?" code out of the function that gets run when the event fires, so it only checks when the addon loads, but doesn't check again when the player's money changes.

Code:
-- DELETE THIS:
money = math.floor(GetMoney()/10000) .. "g"
 
local function TinyMainbarInfo_OnEvent(self, event, ...)
        if event == "PLAYER_ENTERING_WORLD" then
                -- money, durability, ilvl
                -- ADD THIS:
                local money = math.floor(GetMoney() / 10000) .. "g"
                self.moneyText:SetText(money,10)
                -- REMOVE THE ,10 ABOVE
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
09-26-14, 02:18 AM   #11
Danielps1
Guest
Posts: n/a
thanks! works like a charm.

Stuff like this happens If you have no clue what you are doing. I'm going to be more careful what I change next time.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Limit string length


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off