v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

Difference between revisions of "User:Sphr/test/test3"

From Dwarf Fortress Wiki
Jump to navigation Jump to search
m
m
Line 1: Line 1:
array test:
+
=array test=
  
1d array
+
==1d array==
 
+
array-data:{{msgnw:User:Sphr/test/test4}}
<pre>{{:User:Sphr/test/test4}}</pre>
 
{{msgnw:User:Sphr/test/test4}}
 
  
 
{{:User:Sphr/test/test4|0}}
 
{{:User:Sphr/test/test4|0}}
  
 
*array1_size : {{:User:Sphr/f/array1_size| :User:Sphr/test/test4 }}
 
*array1_size : {{:User:Sphr/f/array1_size| :User:Sphr/test/test4 }}
*{{:User:Sphr/test/test4|1}}
+
*elem[1] = {{:User:Sphr/test/test4|1}}
*{{:User:Sphr/test/test4|2}}
+
*elem[2] = {{:User:Sphr/test/test4|2}}
*{{:User:Sphr/test/test4|3}}
+
*elem[3] = {{:User:Sphr/test/test4|3}}
*{{:User:Sphr/test/test4|4}}
+
*elem[4] = {{:User:Sphr/test/test4|4}}
*{{:User:Sphr/test/test4|5}}
+
*elem[5] = {{:User:Sphr/test/test4|5}}
*{{:User:Sphr/test/test4|6}}
+
*elem[6] = {{:User:Sphr/test/test4|6}}
*{{:User:Sphr/test/test4|7}}
+
*elem[7] = {{:User:Sphr/test/test4|7}}
*{{:User:Sphr/test/test4|8}}
+
*elem[8] = {{:User:Sphr/test/test4|8}}
*{{:User:Sphr/test/test4|9}}
+
*elem[9] = {{:User:Sphr/test/test4|9}}
 
 
==notes==
 
notes:
 
 
 
have to use subst.  how to do it by reference? 
 
 
 
Possibly order of evaluation is outside in, which prob results in <nowiki>{{subst:User:Sphr/test/test4}}</nowiki> not being evaluated first.
 
 
 
:I think you're correct about evaluation order. I think this could be solved by making the [[User:Sphr/f/array2_elem]] function recieve a reference instead of trying to pass the entire array. [[User:VengefulDonut|VengefulDonut]] 13:15, 8 January 2008 (EST)
 
::lol, this is not really a programming language.  There is no "passing" of variables by reference or otherwise.  It is more like lexical substitution.  Thus, I don't have a good way to solve the above problem yet.  If only I know a way to do substring extraction in mediawiki..... -- [[User:Sphr|Sphr]] 21:40, 8 January 2008 (EST)
 
:::I think I explained myself poorly. I thought the analogy was clearer. Since you can't substitute a line of text into a template's input (order of evaluation is wrong), you can instead include the name of another template and have your array template extract the element from there. The simplest example I can think of:
 
*replace the outside {{{x}}} of [[User:Sphr/f/array2_elem]] with {{{{{5}}}|x}}. (the x refers to everything in between).
 
* use <nowiki>{{:User:Sphr/f/array2_elem|0|0|3|3|:User:Sphr/test/test4}}</nowiki>.
 
* change [[User:Sphr/test/test4]] to <nowiki>{{:User:Sphr/test/test4/{{{1}}}}}</nowiki>
 
* put the nececcary things in test4's subpages
 
* <nowiki>{{:User:Sphr/f/array2_elem|0|0|3|3|:User:Sphr/test/test4}}</nowiki> will evaluate on the array page as <nowiki>{{:User:Sphr/test/test4|5}}</nowiki> which will evaluate as <nowiki>{{:User:Sphr/test/test4/5}}</nowiki>.
 
This is a dirty fix to demonstrate the idea; you could probably find something much cleaner. [[User:VengefulDonut|VengefulDonut]] 00:58, 9 January 2008 (EST)
 
::ok. just to get myself orientated.  From what you described, it seems that I must breakup the content of an "array" into subpages?  That has been something that I wanted to avoid.  Actually trying to see if there's a way to store and use "arrayed" data in an easier manner and I think creating one subpage for each element is a little overkill.  Still, the need for subst atm is limiting but still somewhat useful in cases where we just need a one-time insertion of data without need to look it up.  But maybe the real solution is to await the upgrade of wiki engine to support the newer parser functions.... -- [[User:Sphr|Sphr]] 02:22, 9 January 2008 (EST)
 
:::I'm not sure if necessary to use subpages or not. It was the first thing I thought of to make the example function. My gut tells me there must be a way to make a single page that dynamically returns one element from a set. [[User:VengefulDonut|VengefulDonut]] 10:39, 9 January 2008 (EST)
 
:::Oh! Subpages aren't necessary. Just implement the same system you're using for the array (it seems a bit arcane to me) to make that happen :). So..
 
:::*Page a: <nowiki>{{:page b|0|0|3|3|:page c))</nowiki>
 
:::*Page b: <nowiki>(mysterious voodoo that evaluates to {{:page c|(elementnumber)}})</nowiki>
 
:::*Page c: <nowiki>{{:page d|(elementnumber)|(array elements divided by |'s)}}</nowiki>
 
:::*Page d: <nowiki>{{{ {{inc {{{1}}} }} }}}</nowiki>
 
:::"Mysterious voodoo" refers to what is on this page: [[User:Sphr/f/array2_elem]]. I don't really understand it, but I know it can be implemented in this way :) [[User:VengefulDonut|VengefulDonut]] 10:52, 9 January 2008 (EST)
 
:::: Actually, what you've described is basically what I've been trying :)  The problem now is in the "array elements divided by |'s)".  When formatted as current (and as described as yours), the whole chunk of | delimited data gets treated as 1 parameter instead of many parameters.  so the {{{x}}} at the last step doesn't work coz the number of param is only 2 (1 for the index we want, and 2 which is the whole chunk of | delimited stuff).  think to make it free of "subst", what we need now is actually a way to reinterpret a chunk of text as proper template invocation again... or a way to represent "the rest of the elements" with what mediawiki provides now (which seems unlikely).  -- [[User:Sphr|Sphr]] 12:08, 9 January 2008 (EST)
 
:::::What I've described is very similar to what you've been trying. Its analogous to passing a variable to a function by reference instead of over the stack. I will try to build a working model to convince you. [[User:VengefulDonut|VengefulDonut]] 01:49, 10 January 2008 (EST)
 
:::::Done. [[User:VengefulDonut/experiment/b]] is "page b". [[User:VengefulDonut/experiment/c]] contains all the array information. [[User:VengefulDonut|VengefulDonut]] 02:07, 10 January 2008 (EST)
 
 
 
3x3 array (row|col|data) : 3|3|a|b|c|d|e|f|g|h|i
 
 
 
element(0,0): {{:User:VengefulDonut/experiment/b|0|0|3|3|:User:VengefulDonut/experiment/c}}
 
 
 
element(0,1): {{:User:VengefulDonut/experiment/b|0|1|3|3|:User:VengefulDonut/experiment/c}}
 
 
 
element(0,2): {{:User:VengefulDonut/experiment/b|0|2|3|3|:User:VengefulDonut/experiment/c}}
 
 
 
element(1,0): {{:User:VengefulDonut/experiment/b|1|0|3|3|:User:VengefulDonut/experiment/c}}
 
 
 
element(1,1): {{:User:VengefulDonut/experiment/b|1|1|3|3|:User:VengefulDonut/experiment/c}}
 
 
 
element(1,2): {{:User:VengefulDonut/experiment/b|1|2|3|3|:User:VengefulDonut/experiment/c}}
 
  
element(2,0): {{:User:VengefulDonut/experiment/b|2|0|3|3|:User:VengefulDonut/experiment/c}}
+
==2d array==
 +
*{{:User:Sphr/f/array2_index|1|1|3|3}}
 +
*{{:User:Sphr/f/array2_index|1|2|3|3}}
 +
*{{:User:Sphr/f/array2_index|1|3|3|3}}
 +
*{{:User:Sphr/f/array2_index|2|1|3|3}}
 +
*{{:User:Sphr/f/array2_index|2|2|3|3}}
 +
*{{:User:Sphr/f/array2_index|2|3|3|3}}
 +
*{{:User:Sphr/f/array2_index|3|1|3|3}}
 +
*{{:User:Sphr/f/array2_index|3|2|3|3}}
 +
*{{:User:Sphr/f/array2_index|3|3|3|3}}
  
element(2,1): {{:User:VengefulDonut/experiment/b|2|1|3|3|:User:VengefulDonut/experiment/c}}
 
  
element(2,2): {{:User:VengefulDonut/experiment/b|2|2|3|3|:User:VengefulDonut/experiment/c}}
+
array-data:{{msgnw:User:Sphr/test/test5}}
 +
*array2_size1 : {{:User:Sphr/f/array2_size1| :User:Sphr/test/test5 }}
 +
*array2_size2 : {{:User:Sphr/f/array2_size2| :User:Sphr/test/test5 }}
 +
*elem[1,1] = {{:User:Sphr/test/test5|1|1}}
 +
*elem[1,2] = {{:User:Sphr/test/test5|1|2}}
 +
*elem[1,3] = {{:User:Sphr/test/test5|1|3}}
 +
*elem[2,1] = {{:User:Sphr/test/test5|2|1}}
 +
*elem[2,2] = {{:User:Sphr/test/test5|2|2}}
 +
*elem[2,3] = {{:User:Sphr/test/test5|2|3}}
 +
*elem[3,1] = {{:User:Sphr/test/test5|3|1}}
 +
*elem[3,2] = {{:User:Sphr/test/test5|3|2}}
 +
*elem[3,3] = {{:User:Sphr/test/test5|3|3}}
  
::::::Ah, I see. So the trick here is to embed the element extraction directly into the "data" template itself from the beginning, which would take away the problem of another template not being able to "split" the data after that... That's very clever! lol... let me sort through all these a little... could be interesting what stuff we can come up with.  I was originally thinking of a way to store unit floor plans (e.g. 3x3 masons workshop) and have a easy way to "recall" this unit floor plan in a bigger design plan (instead of the traditional way of using actual character, I was hoping to do things like mason_workshop[r,c] to recall the characters stored in another data template, so that when that unit floor plan is updated, all dependent floor plans will reflect the change... or something like that.  Really thanks for your help, as I am still very new to mediawiki template (just picked it up like a few days ago) and would be hard-pressed to sort out the implementation issues.  I'm not sure if my plan is still feasible but I'll take some time to see how best to incorporate your solution.  In the mean time, if you want to play around with the very very small set of functions I added, you can look at the list at [[User:Sphr/f]] -- [[User:Sphr|Sphr]] 04:12, 10 January 2008 (EST)
+
(notes moved to talk)

Revision as of 15:56, 11 January 2008

array test

1d array

array-data:{{ User:Sphr/f/array1_elem | {{{1}}} |9|a|b|c|d|e|f|g|h|i}}

9

  • array1_size : 9
  • elem[1] = a
  • elem[2] = b
  • elem[3] = c
  • elem[4] = d
  • elem[5] = e
  • elem[6] = f
  • elem[7] = g
  • elem[8] = h
  • elem[9] = i

2d array

  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13


array-data:{{ User:Sphr/f/array2_elem|{{{1}}}|{{{2}}}|3|3|r1c1|r1c2|r1c3|r2c1|r2c2|r2c3|r3c1|r3c2|r3c3 }}

  • array2_size1 : 3
  • array2_size2 : 3
  • elem[1,1] = r1c1
  • elem[1,2] = r1c2
  • elem[1,3] = r1c3
  • elem[2,1] = r2c1
  • elem[2,2] = r2c2
  • elem[2,3] = r2c3
  • elem[3,1] = r3c1
  • elem[3,2] = r3c2
  • elem[3,3] = r3c3

(notes moved to talk)