How to pass a variable into the lesson?

For general questions about Content Authoring

Moderator: Nav

How to pass a variable into the lesson?

Postby ir0nman » Thu Aug 09, 2012 11:02 am

Hi. I was wondering if there is any way I would be able to pass information through into a lesson?

I want to be able to pass through a user ID into the lesson, so when a specific user finishes the lesson, I can use posttoURL to send user_id and the final score.

I was thinking of using cookies, however I noticed that there's only a setCookie option, and no readcookie option.. any suggestions?
ir0nman
 
Posts: 4
Joined: Wed Aug 08, 2012 9:53 pm

Re: How to pass a variable into the lesson?

Postby Nav » Thu Aug 09, 2012 11:58 am

Hi John,
There is a getCookie method, but it won't show up until you have a place to put it. For example, if you wanted to put it in a text object, or a variable.

Response: Text Variable > setValue > Function > Cookie object > getCookie ...

However, I'm not sure cookies is the way to go.

The biggest question is - Where would you be getting the userID from?

The server? Have they already logged in before getting access to the lesson? If so, then you could just query the database for the userID. Or, since they've already logged in, do you even need to get and re-send the userID?

If the learner does not have to login before accessing the lesson, then most likely they'll have to enter it into the lesson. Probably with a InputText object.

Let me know a little more about the structure surrounding the lesson and I can be more specific. You can also email suppor@suddenlysmart directly if you do not want to post this information here are the forum.

- Nav
Nav
 
Posts: 866
Joined: Mon Nov 05, 2007 2:58 pm

Re: How to pass a variable into the lesson?

Postby ir0nman » Thu Aug 09, 2012 2:41 pm

The user ID will be coming from a pre-loaded html select box that contains specific staff members (and their user IDs) based on a certain office login account. (One login account for multiple users)

So what I was planning to implement was (since there is only one user login for multiple user IDs tied to that specific login)a staff member would goto a page where they can select their name from the list, click a button to 'start the lesson' , and then the lesson would load, with the user_id and name of the staff member being passed through into the lesson (from a cookie)

Does that kind of make sense?
ir0nman
 
Posts: 4
Joined: Wed Aug 08, 2012 9:53 pm

Re: How to pass a variable into the lesson?

Postby Nav » Fri Aug 10, 2012 4:02 pm

Hmm, I think it makes sense. So all the login and selection stuff is done before the SmartBuilder lesson even launches? Then yes, you could probably create a cookie, and then have SmartBuilder fetch it and load it into a variable.

Do you already know how to set the cookie (outside SmartBuilder)? And are you set with the Cookie object's getCookie method? Or would you like to take a look at this issue together?

- Nav
Nav
 
Posts: 866
Joined: Mon Nov 05, 2007 2:58 pm

Re: How to pass a variable into the lesson?

Postby ir0nman » Wed Aug 15, 2012 2:46 pm

Yes. I do know how to set a cookie outside smartbuilder. I will try to see if i can receive the cookie information within the smartbuilder lesson
ir0nman
 
Posts: 4
Joined: Wed Aug 08, 2012 9:53 pm

Re: How to pass a variable into the lesson?

Postby ir0nman » Wed Aug 15, 2012 4:11 pm

Ok, so I've tried reading the cookie value I've set, but no luck. Here is the cookie I've set before I redirect to the lesson:

setcookie("ecourse[user_name]", "John Doe", time()+3600, "/");

Inside the lesson, on the first page, I have included a cookie object and a input text box. I add a condition for the input text box: Input Text 1 > setText > Cookie Object > getCookie. For the "name" field i put 'ecourse[user_name]' (without quotes) and for the "path field" i put '/' (without quotes). I save the lesson, publish it, and run it, but it does not fill in the textbox with the cookie.. Any idea why its not working?
ir0nman
 
Posts: 4
Joined: Wed Aug 08, 2012 9:53 pm

Re: How to pass a variable into the lesson?

Postby Nav » Tue Aug 21, 2012 1:15 pm

Hi John,
Sorry for the delay getting back to you. I'm no coding expert, but isn't the part in brackets a variable? So, the Cookie name that is being saved isn't hard-coded, right?

Well, that's fine, but the SmartBuilder Cookie object isn't using whatever coding language you're using. So looking for a Cookie called ecourse[user_name] is probably not going to work.

Rather than making the name of the Cookie variable, can you use a constant name, and make the value change?

For example, we save a bookmark using a php script with the following:

Code: Select all
//echo $_GET["page"];
setcookie("help-pageNumber",$_GET["page"],time()+120);

And so we always look for the Cookie called help-pageNumber.

So try it with a constant Cookie name and let us know what you find. Maybe try testing it in Firefox, as you can look up individual Cookies (Tools > Options > Privacy tab > remove individual cookies). You can also try using the SmartBuilder Cookie object to write a Cookie, and use FF to find it and see if it looks any different than the one that you're creating.

Once again, this is probably easier to troubleshoot over a gotomeeting, so let me know if you want to go that route.

- Nav
Nav
 
Posts: 866
Joined: Mon Nov 05, 2007 2:58 pm


Return to General

Who is online

Users browsing this forum: No registered users and 3 guests

cron
Not able to open ./cache/data_global.php