ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Wolfgang Schuster <wolfgang.schuster.lists@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>,
	ai2472206007@yeah.net
Subject: [NTG-context] Re: Numbers obtained by commands <\datasetvariable> cannot be copied to counters
Date: Wed, 29 May 2024 16:30:51 +0200	[thread overview]
Message-ID: <ecb97a10-55ad-b5f7-25e2-a5bb79466beb@gmail.com> (raw)
In-Reply-To: <171698432131.1996.6583951499689676818@cgl.ntg.nl>

ai2472206007@yeah.net schrieb am 29.05.2024 um 14:05:
> I'm defining a command to generate options for multiple choice questions,
> but at the moment I'm stuck at this step.
> I want to get a number and assign a value to the counter, but why can't I get it?
> 
> %%%%
> \starttext
> \definedataset [myset]
> \setdataset    [myset] [foo=1,boo=4]
> \newcount\tempa
> \datasetvariable{myset}{1}{boo} % definitely get 4
> %\tempa=\datasetvariable{myset}{1}{boo} % why i cannt pass 4 to tempa?
> %\number\tempa
> \stoptext
> %%%%%
> 
> If anyone can fix it, thanka very much

You have to add a check to ensure there is a value stored in the 
aux-file before you pass the value to the counter. This is necessary 
because when you process the document for the first time Context only 
saves the value and can access it only in the next run after.

%%%% begin example
\definedataset [myset]

\starttext

\setdataset [myset] [foo=1,boo=4]

\doifelsesomething{\datasetvariable{myset}{1}{boo}}
   {\scratchcounter\datasetvariable{myset}{1}{boo}}
   {\scratchcounter\zerocount}

boo = \number\scratchcounter

\stoptext
%%%% end example

Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

  parent reply	other threads:[~2024-05-29 14:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-29 12:05 [NTG-context] " ai2472206007
2024-05-29 12:48 ` [NTG-context] " Taco Hoekwater
2024-05-29 14:32   ` ai2472206007
2024-05-29 14:30 ` Wolfgang Schuster [this message]
2024-05-29 14:33   ` ai2472206007
2024-05-29 15:20 ` ai2472206007

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ecb97a10-55ad-b5f7-25e2-a5bb79466beb@gmail.com \
    --to=wolfgang.schuster.lists@gmail.com \
    --cc=ai2472206007@yeah.net \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).