"Global Variables" in Lectora

mlapl1
mlapl1 Community Member Posts: 349
Hello

In order to avoid confusion, I would like to use the same variable across several pages, let's call it Student_Answer. But Lectora will not let me do this at least in the following example. I have a number of entry fields in the lesson. If I try to rename the variable created by Lectora for the entry field to the name of the variable I want to be able to re-use, Lectora complains that the variable exists already.

The reason I want to re-use the variable is that I want a "naive" user simply to copy a page that works already and just set the values of some variables using the Lectora facilities and not have to mess about with Javascript etc.

Any workarounds for this? Thanks.

 

Comments

  • mnotermans5114
    mnotermans5114 Community Member Posts: 916
    Hi Andrew,

    Several options for this. What i would do is fix my javascript so it doesnot check for a specific name of a variable like Entry_0001, but instead get all entryfields from page(s), check some of my samples... in the javascript you find a function getHTMLNamesFromLectora, that function processes a page and gets all images and texts. If you add a entryArray, and push all textfields with entry into that, you got them all.

    Then you can generate the variables you need to check/process from the entry-textfields.

    If you add a sample of what your trying to get done including awt onhere... i will see if i can fix it.

    Kind regards,

    Math
  • mnotermans5114
    mnotermans5114 Community Member Posts: 916
    Another 'sneaky' option ( i just tried it ;-) is changing the entry-fields var name in the .awt

    So save the awt as is. Open it up as xml in a text-editor, change the vars-names from entry_0001,0002,0003 etc. to globalEntry_0001 and bingo... no complaining of Lectora, opening the awt up again you notice all entryfields do have the same var name.

    Adding my quick and dirty test.

    I am not sure if this fixes your problems Andrew, if so good...if not..let me know :-)

    Kind regards,
    Math
  • mlapl1
    mlapl1 Community Member Posts: 349
    Thank you so much Math. Smart as usual! I had a look at the files that came with the second message but could not find any reference to what you had suggested in your first message. On the other hand, this all makes it clear to me that the problem is with the assignment of variables to entry fields. Other variables are actually global so all we need is one (or occasionally two) assignment(s) and the rest all stays the same.

    Thanks a lot

    Andrew
  • timk
    timk Community Member Posts: 1,195 ♦ Idol ♦
    You can just assign the same variable to several entry fields by selecting it from the dropdown.

    Tim
  • mnotermans5114
    mnotermans5114 Community Member Posts: 916
    Ok Nice Tim... but i guess i miss something basic... cause when i add a custom variable...i dont see it in the properties for the entryfield variables...

     

     
  • mnotermans5114
    mnotermans5114 Community Member Posts: 916
    Duhh...ok sometimes i overlook the simple things ;-)

    When adding a variable...you dont have acces to it in the dropdown. When changing its name in the textfield ..well then indeed like Tim said you can set the other inputfields to the same variable...

    Done it before...and now overlooking it ;-)
  • timk
    timk Community Member Posts: 1,195 ♦ Idol ♦
    You can only create that variable via the field in the entryfields properties, because it's not a "User-Defined" variable. It's listed under "Reserved".

    Tim
  • mnotermans5114
    mnotermans5114 Community Member Posts: 916
    Yeah missed that ;-)
  • mlapl1
    mlapl1 Community Member Posts: 349
    Thank you both very much - I really appreciate your assistance on this.

    Andrew