Loading ...
Sorry, an error occurred while loading the content.

I'm lost trying to assign a variable.

Expand Messages
  • Eric Jackson
    Ok I have a script that is trying to generate trade info between planets. So far I have: var pop,startpop,endpop, PassValue, SName; getFileName
    Message 1 of 3 , Mar 13, 2013
    • 0 Attachment

      Ok I have a script that is trying to generate trade info between planets.

       

      So far I have:

       

      <stuff>

      var pop,startpop,endpop, PassValue, SName;

       

      getFileName fileName, "Select Destination System", "*.chr";

      pop=substr(getfilevalue(fileName,"UWP"),5,1);

      startpop=$@CurrentPassMod;

      SName=$@SystemName;

      endpop=getfilevalue(fileName,"DestPassMod");

      PassValue = HexToDec(pop) + (startpop+endpop);

      dialog ok, Dialog Title;

                     text Trade Report:;

                     text ;

                     displayexp "format('From %s  to %s',SName)";

                     text Passengers:;

                     displayexp "format('Population: %d  Start Mod: %d   End Mod: %d   Value: %d', HexToDec(pop),startpop, endpop, PassValue)";

                     end

       

      The problem is the value of SName is always 0, even though $@SystemName is equal to “Feri”. Running the script debugger right before the dialog here are the variables:

       

      Endpop: “+4”

      Filename: “C:/Users/Eric/Skydrive/Traveller/System Data/Entrope.chr”

      HexToDec()

      isOnNew: 0

      PassValue: 0

      Pop: “A”

      SName: 0

      Startpop: -1

       

      Why won’t SName take the proper value?

    • Bruce Kvam
      The reason you re seeing this behavior is that references with $@ are purely textual substitutions, not variable references. (That s so you can use such
      Message 2 of 3 , Mar 14, 2013
      • 0 Attachment
        The reason you're seeing this behavior is that references with $@ are purely textual substitutions, not variable references. (That's so you can use such references in the text parts of dialog boxes.) Since the value of SystemName is a string, what you're doing is assigning sname=Feri, instead of sname="Feri".

        Perhaps the most reliable way of referencing values in the character sheet from a script is use eval with three arguments.

        In your case you would use the following assignment:

            sname=eval('SystemName', 0, 1);



        On 3/14/13 12:06 AM, Eric Jackson wrote:

        Ok I have a script that is trying to generate trade info between planets.

         

        So far I have:

         

        <stuff>

        var pop,startpop,endpop, PassValue, SName;

         

        getFileName fileName, "Select Destination System", "*.chr";

        pop=substr(getfilevalue(fileName,"UWP"),5,1);

        startpop=$@CurrentPassMod;

        SName=$@SystemName;

        endpop=getfilevalue(fileName,"DestPassMod");

        PassValue = HexToDec(pop) + (startpop+endpop);

        dialog ok, Dialog Title;

                       text Trade Report:;

                       text ;

                       displayexp "format('From %s  to %s',SName)";

                       text Passengers:;

                       displayexp "format('Population: %d  Start Mod: %d   End Mod: %d   Value: %d', HexToDec(pop),startpop, endpop, PassValue)";

                       end

         

        The problem is the value of SName is always 0, even though $@SystemName is equal to “Feri”. Running the script debugger right before the dialog here are the variables:

         

        Endpop: “+4”

        Filename: “C:/Users/Eric/Skydrive/Traveller/System Data/Entrope.chr”

        HexToDec()

        isOnNew: 0

        PassValue: 0

        Pop: “A”

        SName: 0

        Startpop: -1

         

        Why won’t SName take the proper value?


      • Eric Jackson
        Ahhh, Ok I see what was going on. I m moving forward with my script, I m sure I ll have more questions. ;) From: cw@yahoogroups.com [mailto:cw@yahoogroups.com]
        Message 3 of 3 , Mar 17, 2013
        • 0 Attachment

          Ahhh, Ok I see what was going on.

           

          I’m moving forward with my script, I’m sure I’ll have more questions… ;)

           

          From: cw@yahoogroups.com [mailto:cw@yahoogroups.com] On Behalf Of Bruce Kvam
          Sent: Thursday, March 14, 2013 8:24 AM
          To: cw@yahoogroups.com
          Subject: Re: [cw] I'm lost trying to assign a variable.

           

           

          The reason you're seeing this behavior is that references with $@ are purely textual substitutions, not variable references. (That's so you can use such references in the text parts of dialog boxes.) Since the value of SystemName is a string, what you're doing is assigning sname=Feri, instead of sname="Feri".

          Perhaps the most reliable way of referencing values in the character sheet from a script is use eval with three arguments.

          In your case you would use the following assignment:

              sname=eval('SystemName', 0, 1);



          On 3/14/13 12:06 AM, Eric Jackson wrote:

          Ok I have a script that is trying to generate trade info between planets.

           

          So far I have:

           

          <stuff>

          var pop,startpop,endpop, PassValue, SName;

           

          getFileName fileName, "Select Destination System", "*.chr";

          pop=substr(getfilevalue(fileName,"UWP"),5,1);

          startpop=$@CurrentPassMod;

          SName=$@SystemName;

          endpop=getfilevalue(fileName,"DestPassMod");

          PassValue = HexToDec(pop) + (startpop+endpop);

          dialog ok, Dialog Title;

                         text Trade Report:;

                         text ;

                         displayexp "format('From %s  to %s',SName)";

                         text Passengers:;

                         displayexp "format('Population: %d  Start Mod: %d   End Mod: %d   Value: %d', HexToDec(pop),startpop, endpop, PassValue)";

                         end

           

          The problem is the value of SName is always 0, even though $@SystemName is equal to “Feri”. Running the script debugger right before the dialog here are the variables:

           

          Endpop: “+4”

          Filename: “C:/Users/Eric/Skydrive/Traveller/System Data/Entrope.chr”

          HexToDec()

          isOnNew: 0

          PassValue: 0

          Pop: “A”

          SName: 0

          Startpop: -1

           

          Why won’t SName take the proper value?

           

        Your message has been successfully submitted and would be delivered to recipients shortly.