5E Product Walkthrough Playlist
Page 2 of 3 First 123 Last
  1. #11
    Quote Originally Posted by MadBeardMan View Post
    Yes you will need to add it to the script wherever you 'build' your dice pool.
    Ok, so it doesn’t need its own file in, say, “campaign/scripts/example.lua”?
    Sorry, just making sure I understand

  2. #12
    The example I gave you is the script section of the template code.

    For example here's something similar from Traveller, this is for rolling the Initiative:
    Code:
            <template name="number_initiative">
       		<simplenumber>
    			<source mergerule="resetandadd" />
    			<script file="common/scripts/number_linked.lua" />
    			<frame mergerule="replace" name="fielddark" offset="7,5,7,5" />
    			<stateframe>
    				<keyedit name="fieldfocus" offset="7,5,7,5" />
    				<hover name="fieldfocus" offset="7,5,7,5" hidereadonly="true" />
    				<drophilight name="fieldfocus" offset="7,5,7,5" hidereadonly="true" />
    			</stateframe>		
    			<script>
    				function action(draginfo)
    					local rActor = ActorManager.getActor("pc", window.getDatabaseNode());
    					ActionInit.performRoll(draginfo, rActor);
    
    					return true;
    				end
    				
    				function onDragStart(button, x, y, draginfo)
    					return action(draginfo);
    				end
    					
    				function onDoubleClick(x,y)
    					return action();
    				end
    			</script>				
    			<rollable />	
    		</simplenumber>
    	</template>
    I can take a look at your stuff in your original posting but it's late here (11pm) and so I'm logging for the night.

    Hope you can make progress

    Cheers,
    MBM
    Ruleset and much more content built for FGU.
    Come join me on Twitter at: https://twitter.com/MadBeardMan to see what I'm up to!

  3. #13
    uhg, i can't seem to get it to work.

    i might be doing this quite wrong, as i say, i have little to no experience with xml/lua so please forgive me if i'm a pain in the butt about this.

    i tried copying the code directly into the <basicnumber name="stressroll" source="stressroll.slot.amount"> spot, and tried modifying to suit my code where needed. but i think part of my problem is that i can't seem to figure out how to get the variable number from the <basicnumber> i'm writing the script into.

    like i say, maybe i'm doing this wrong. perhaps i need to do up a template? because what i have now is all right in the record_char_main2.xml within the charsheet_main2 window. all the frames, <basicnumber>'s, and such are directly in there, i don't have a template "attributescore" or "attributecheck". i've been scripting directly into:

    record_char_main2.xml (a copy of the CoreRPG "record_char_main.xml")
    <window name="charsheet_main2">
    <basicnumber name="stressroll" source="stressroll.slot.amount">
    <script>
    i've been putting my code in here
    </script>
    </basicnumber>
    <window>

    i feel like i'm close. i feel like trenloe's addition with the "for" commands was close to working, but i can't seem to reference the <basicnumber> from which i'm coding in. i can't seem to reference any numberfield source. so how do i set up the variable? from other examples i've seen, the following should theoretically work:

    nDice = getValue();

    but it often can't reference the "global: getValue()"

    i tried MadBearMan's code, and i still may not know what to change, such as the ActionInit, i tried ActionManager to no avail.

    if someone can help me figure out the Stress Roll part, then maybe i can figure out the rest of it. i just can't figure out how to assemble this.

    (note, i will want other rolls to include the stressroll if the stresspoints are above 0)

    stress points are in the "Alien RPG\campaign\record_char_main2.xml" file, starting at line 41, ending at line 81. the <basicnumber> section starts at line 61.
    Last edited by pr6i6e6st; August 9th, 2019 at 06:59.

  4. #14
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,408
    Quote Originally Posted by pr6i6e6st View Post
    nDice = getValue();

    but it often can't reference the "global: getValue()"
    getValue(); should work - as long as the LUA script is running within the context of the control. If it's running in the window you'll need to use <control name>.getValue() - for example, stressroll.getValue();

    Quote Originally Posted by pr6i6e6st View Post
    i tried MadBearMan's code, and i still may not know what to change, such as the ActionInit, i tried ActionManager to no avail.
    ActionInit is a predefined action. Actions are the usual way to do dice rolling in FG. See here for details of FG actions: https://www.fantasygrounds.com/forum...(dice-rolling)
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  5. #15
    Quote Originally Posted by Trenloe View Post
    getValue(); should work - as long as the LUA script is running within the context of the control. If it's running in the window you'll need to use <control name>.getValue() - for example, stressroll.getValue();
    i feel like this is what's holding me up the most really. the console keeps returning "script Error: [string"stressroll"]:1 attempt to call global 'getValue' (a nil value)" for just putting:
    <script>
    local nDice = getValue();
    </script>

    so i'm missing something here, because you say that should work, and i believe you, it looks like it should. but for some reason, it's not? i'll have to check back later.

    thanks for being patient, sorry if you've explained yourself and i'm not grasping it.

  6. #16
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,408
    Quote Originally Posted by pr6i6e6st View Post
    <script>
    local nDice = getValue();
    </script>
    You can't just have code in a script by itself. It needs to be in a function and that function needs to be either called from somewhere else, or tied to an event (buttonClick, onUpdate, etc.). FG is primarily an event driven application - something happens to trigger one or more events that do something else.

    There are many events within FG - the exact event you can tie code off will depend on the control that's triggering the event.

    In your code in post #1 you were using the onDoubleClick event - which is a good start. Details on that event here: https://www.fantasygrounds.com/refdo...#onDoubleClick
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  7. #17
    Quote Originally Posted by Trenloe View Post
    You can't just have code in a script by itself. It needs to be in a function and that function needs to be either called from somewhere else, or tied to an event (buttonClick, onUpdate, etc.). FG is primarily an event driven application - something happens to trigger one or more events that do something else.

    There are many events within FG - the exact event you can tie code off will depend on the control that's triggering the event.

    In your code in post #1 you were using the onDoubleClick event - which is a good start. Details on that event here: https://www.fantasygrounds.com/refdo...#onDoubleClick
    ok i think i'm kind of getting it, but i think i'm not referring to aDice properly or something here. i've tried a few different variations of (aDice), aDice, {aDice}, "aDice". ({" aDice "}) crashed the program haha. so what's off here?

    Code:
    <script>
    					function onDragStart(button, x, y, dragdata)
    						
    						local nTotal = getValue().."dS";
    						local aDice, nMod = StringManager.convertStringToDice(nTotal);
    	
    						local bDescNotEmpty = true;
    						local sStackDesc, nStackMod = ModifierStack.getStack(bDescNotEmpty);
    		
    						local modifierDice = nStackMod;
    
    						if modifierDice > 0 then
    							for i=1,modifierDice do
    								table.insert(aDice, "dS");
    							end
    						else
    							for i=1,-modifierDice do
    								table.remove(aDice);
    							end
    						end
    						dragdata.setType("dice");
    						dragdata.setDieList(aDice);
    						dragdata.setNumberData(getValue());
    						dragdata.setDescription("Stress Roll");
    					
    						return true;
    					end
    					
    					function onDoubleClick(x,y)
    						local nTotal = getValue().."dS";
    						local aDice, nMod = StringManager.convertStringToDice(nTotal);
    	
    						local bDescNotEmpty = true;
    						local sStackDesc, nStackMod = ModifierStack.getStack(bDescNotEmpty);
    		
    						local modifierDice = nStackMod;
    
    						if modifierDice > 0 then
    							for i=1,modifierDice do
    								table.insert(aDice, "dS");
    							end
    						else
    							for i=1,-modifierDice do
    								table.remove(aDice);
    							end
    						end
    						Comm.throwDice( "dice", aDice, getValue(), description)
    					end
    					
    				</script>

  8. #18
    NEVERMIND!!! I GOT IT! Holy crap i got it! Thank You guys SO MUCH!

    Code:
    <script>
    					function onDragStart(button, x, y, dragdata)
    						local description = "Stress Roll"
    						local nValue = getValue();
    						local aDice, nMod = StringManager.convertStringToDice(nTotal);
    	
    						local bDescNotEmpty = true;
    						local sStackDesc, nStackMod = ModifierStack.getStack(bDescNotEmpty);
    		
    						local modifierDice = nStackMod;
    
    						if nValue > 0 then
    							for i=1,nValue do
    								table.insert(aDice, "dS");
    							end
    						else
    							for i=1,-nValue do
    								table.remove(aDice);
    							end
    						end
    						dragdata.setType("dice");
    						dragdata.setDieList(aDice);
    						dragdata.setNumberData(getValue());
    						dragdata.setDescription("Stress Roll");
    						return true;
    					end
    					
    					function onDoubleClick(x, y)
    						local nValue = getValue();
    						local nTotal = getValue().."dS";
    						local aDice, nMod = StringManager.convertStringToDice(nTotal);
    	
    						local bDescNotEmpty = true;
    						local sStackDesc, nStackMod = ModifierStack.getStack(bDescNotEmpty);
    		
    						local modifierDice = nStackMod;
    
    						if nValue > 0 then
    							for i=1,nValue do
    								table.insert(aDice, "dS");
    							end
    						else
    							for i=1,-nValue do
    								table.remove(aDice);
    							end
    						end
    						Comm.throwDice( "dice", aDice, getValue(), description)
    					end
    					
    				</script>

  9. #19
    now if only i could get the description to show in chat for onDragStart. sometimes i can see the text being dragged, but it doesn't return in the chat with the rest. onDoubleClick works.

  10. #20
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,685
    Blog Entries
    1
    aDice is a Lua array.
    It (can) holds multiple pieces of data - eg 1d20, 1d20, 2d20, 1d20

    debug aDice at various stages and see what is outputting

    you are getting different results from onDragStart and onDoubleClick because you are running different things on those events

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
  •  
DICE PACKS BUNDLE

Log in

Log in