STAR TREK 2d20
Page 1 of 2 12 Last
  1. #1

    Forcing text into a labeledstring?

    I've bumped into a problem. I had to add/change some items in the Combat Tracker for my ruleset. Part of this process is dragging some text form labeledstrings to the tracker. I've found that if there is nothing in the labeledstring (that is to say, it hasn't been filled out yet), then I get a nil error message. I'm sure there's a correct way to do it, but the quick and dirty way would be to force some default text into the string.

    Question:
    How to you force some default text into a labeledstring? I checked the documentation and couldn't find an entry for that function.


    Code:
    			<labeledstring name="combatweapons">
    				<anchored>
    					<to>combatminiweaponframe</to>
    					<position>insidetopleft</position>
    					<offset>15,22</offset>
    					<size>
    						<width>190</width>
    					</size>
    				</anchored>
    				<anchorto>overviewframe</anchorto>
    				<label>Weapons</label>
    			</labeledstring>
    Ultimate License
    Rulesets by NezziR:
    WFRP2 for FGI, WFRP2 for FGII, Dark Heresy for FGII,
    Savage Fallout for FGII and Savage Worlds, FGII help mod.


    https://groups.yahoo.com/neo/groups/fgvtt/files

  2. #2

    Join Date
    Feb 2006
    Location
    Fairfax County, Virginia
    Posts
    499
    You might be able to set the text in the object's onInit function. "labeledstring" is a template defined in the default ruleset's "common_templates.xml" file, and it already has an onInit function defined there. "labeledstring" also inherits from the "textbasecontrol" object, which provides the "setValue()" function for setting the contents of the object.

    This is pure hypothesis, by the way, so it may not work

  3. #3
    Quote Originally Posted by Dachannien
    You might be able to set the text in the object's onInit function. "labeledstring" is a template defined in the default ruleset's "common_templates.xml" file, and it already has an onInit function defined there. "labeledstring" also inherits from the "textbasecontrol" object, which provides the "setValue()" function for setting the contents of the object.

    This is pure hypothesis, by the way, so it may not work
    That's two I owe you. I'll see if I can work my way through this. Thanks again.

    Edit: Yeah, I just looked at that. It's a bit beyond me at the moment. My mind says there should be a way to do like an "if nil then" kind of thing, but I don't really know how to do that. I'll poke around in some of the scripts and see if I can reverse engineer something. I'm not really a script writer yet.
    Last edited by nezzir; May 15th, 2007 at 04:19.
    Ultimate License
    Rulesets by NezziR:
    WFRP2 for FGI, WFRP2 for FGII, Dark Heresy for FGII,
    Savage Fallout for FGII and Savage Worlds, FGII help mod.


    https://groups.yahoo.com/neo/groups/fgvtt/files

  4. #4
    Quote Originally Posted by nezzir
    That's two I owe you. I'll see if I can work my way through this. Thanks again.

    Edit: Yeah, I just looked at that. It's a bit beyond me at the moment. My mind says there should be a way to do like an "if nil then" kind of thing, but I don't really know how to do that. I'll poke around in some of the scripts and see if I can reverse engineer something. I'm not really a script writer yet.
    I can't even drag a labeledstring when it's empty... o.0

    However, what will probably work for you is:
    Code:
    	<template name="labeledstring">
    		<stringfield>
    			<font>sheettext</font>
    			<frame>
    				<name>textline</name>
    			</frame>
    			<script>
    				labelwidget = nil;
    			
    				function onInit()
    					if not getValue() then
    						setvalue("")
    					end
    
    					labelwidget = addTextWidget("sheetlabelinline", string.upper(label[1]));
    					
    					local w,h = labelwidget.getSize();
    					labelwidget.setPosition("bottomleft", w/2, h/2-5);
    				end
    			</script>
    		</stringfield>
    	</template>
    Essentially, what that does is:

    If getvalue() returns nil, false, or otherwise something that doesn't equal true, it will then call setValue and pass it an empty string.

    Should fix the problem, but it's not the best way to do it.


    A better way to do it:
    The better bet for dealing with the problem is to deal with nil errors on the receiving control's side. In the control's onDrop handler, just specify that if it's passed a nil value then set it to something there.

    The reason why this is better is because that way it handles if the labeledstring field is somehow not initialized.


    (if you have problems, just give me the error message and the snippet of code that it relates to)
    "He is everything I have ever aspired to be."
    "Your aspiration is to be impaled on a halberd? Your parents must be proud."

  5. #5
    Quote Originally Posted by TarynWinterblade
    A better way to do it:
    The better bet for dealing with the problem is to deal with nil errors on the receiving control's side (I tried it as is and with a value between the quotes). In the control's onDrop handler, just specify that if it's passed a nil value then set it to something there.

    The reason why this is better is because that way it handles if the labeledstring field is somehow not initialized.


    (if you have problems, just give me the error message and the snippet of code that it relates to)
    I tried the
    Code:
    					if not getValue() then
    						setvalue("")
    					end
    (tried it as is and with a value in the quotes) and it didn't work. It blew up all my labeledstrings sheet-wide. I've attached all my combat_tracker scripts in a zip (because I really wasn't sure which one was responsible). If you get a few minutes to browse through them, I'd value your opinion.

    I really gotta stop and teach myself some lua...

    Thanks,
    Nez
    Last edited by nezzir; May 15th, 2007 at 14:48.
    Ultimate License
    Rulesets by NezziR:
    WFRP2 for FGI, WFRP2 for FGII, Dark Heresy for FGII,
    Savage Fallout for FGII and Savage Worlds, FGII help mod.


    https://groups.yahoo.com/neo/groups/fgvtt/files

  6. #6
    Quote Originally Posted by nezzir
    I tried the
    Code:
    					if not getValue() then
    						setvalue("")
    					end
    (tried it as is and with a value in the quotes) and it didn't work. It blew up all my labeledstrings sheet-wide.
    That's... strange. That means that it's returning false for some reason.

    Quote Originally Posted by nezzir
    I've attached all my combat_tracker scripts in a zip (because I really wasn't sure which one was responsible). If you get a few minutes to browse through them, I'd value your opinion.
    What does the error message you're getting say?
    i.e.: "Script error: [scripts/somefile.lua] Tried to do something wrong, somewhere..."
    "He is everything I have ever aspired to be."
    "Your aspiration is to be impaled on a halberd? Your parents must be proud."

  7. #7
    Quote Originally Posted by TarynWinterblade
    What does the error message you're getting say?
    i.e.: "Script error: [scripts/somefile.lua] Tried to do something wrong, somewhere..."
    Script Error: [string "scripts/combattracker.lua"]:68: attempt to index a nil value

    Line 68 of combattracker.lua is:
    newentry.ac.setValue(source.getChild("combatarmor" ).getValue())

    The labeledstring that sets that says:
    Code:
    			<labeledstring name="combatarmor">
    				<anchored>
    					<to>combatminiarmorframe</to>
    					<position>insidetopleft</position>
    					<offset>15,22</offset>
    					<size>
    						<width>190</width>
    					</size>
    				</anchored>
    				<anchorto>overviewframe</anchorto>
    				<label>Armor</label>
    			</labeledstring>
    I get the error until I put something in that string field on the combat page of the character sheet.
    Ultimate License
    Rulesets by NezziR:
    WFRP2 for FGI, WFRP2 for FGII, Dark Heresy for FGII,
    Savage Fallout for FGII and Savage Worlds, FGII help mod.


    https://groups.yahoo.com/neo/groups/fgvtt/files

  8. #8
    So far, just from looking at things (I'm missing a few files - namely the windowclass for the combat tracker... can you attach your utility_combattracker.xml file?)...

    In combattracker.lua:
    Code:
    function onDrop(x, y, draginfo)
    	if draginfo.isType("playercharacter")  then
    		local name = draginfo.getStringData();
    		local source = draginfo.getDatabaseNode();
    		local token = draginfo.getTokenData();
    
    		if source then	
    			local newentry = addPc(name, source, token);
    		end
    
    		return true;
    	elseif draginfo.isType("shortcut")  then
    		-- NPC code...
    	end
    end
    You took out the two lines in red. Don't do that Those lines make sure that you have a valid source node in the DB so that you don't get more errors in addPc().

    Also, you added the parts in blue there, thus passing an extra variable to addPc. Why do you want the name passed like that? The d20 code handles setting the name from the PC's database node (source)... what's different about your ruleset's code that necessitates having the name passed separately?
    "He is everything I have ever aspired to be."
    "Your aspiration is to be impaled on a halberd? Your parents must be proud."

  9. #9
    Quote Originally Posted by nezzir
    Script Error: [string "scripts/combattracker.lua"]:68: attempt to index a nil value

    Line 68 of combattracker.lua is:
    newentry.ac.setValue(source.getChild("combatarmor" ).getValue())

    The labeledstring that sets that says:
    Code:
    			<labeledstring name="combatarmor">
    				<anchored>
    					<to>combatminiarmorframe</to>
    					<position>insidetopleft</position>
    					<offset>15,22</offset>
    					<size>
    						<width>190</width>
    					</size>
    				</anchored>
    				<anchorto>overviewframe</anchorto>
    				<label>Armor</label>
    			</labeledstring>
    I get the error until I put something in that string field on the combat page of the character sheet.
    Ahh. That's not because the string is empty, but rather because source.getChild("combatarmor") returns nil.

    Change your code from:
    Code:
    newentry.ac.setValue(source.getChild("combatarmor").getValue())
    ... to:

    Code:
    if source.getChild("combatarmor") then
    	newentry.ac.setValue(source.getChild("combatarmor").getValue())
    else
    	newentry.ac.setValue("")
    end
    It's odd though, that it would only complain about that particular field.
    "He is everything I have ever aspired to be."
    "Your aspiration is to be impaled on a halberd? Your parents must be proud."

  10. #10
    Also, something to keep in mind:

    In the d20 combat tracker, SmiteWorks coded the fields to keep track of changes in the database node they linked to. Hence, if you changed something with the character they were referencing, it would update on the sheet as well.

    However, by just calling setValue, instead of copying the setLink functionality, you don't trigger the automatic updates.

    Edit: Also, using SW's setLink code would have gotten rid of the error, since their code, by default, checks to see if the node it got passed was nil before attempting anything with it.
    "He is everything I have ever aspired to be."
    "Your aspiration is to be impaled on a halberd? Your parents must be proud."

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
FG Spreadshirt Swag

Log in

Log in