Quiz Game - Counter Function

Hello ZapForum.
I wonder if anyone could help with the following:
I have a quiz game with 10 questions… I don’t normally code so it is a pain really…
I was sent an example of a counter by the lovely support team at Zappar, thank you but I wonder how I can use one script (one function ) and call this function in every question? as support says:
So how to create a a function in a script, and then call it from other scripts in your hierarchy.
if anyone has an example of how to do this please let me know .

Milenne

To make a function, or a variable , accessible from other scripts, you have to "export " it.
Let’s say, you have a blank script named " code " in your hierarchy.
Inside " code " you declare your function myTimer() with the keyword export:

export function myTimer(){ ... }

Then to invoke myTimer() from another script, you just have to give the whole path to the function:

symbol.nodes.code.myTimer();

Of course, you will have also to take care of the timer value.

So, add the variable in " code ":

export var timer;
export function myTimer(){ ... }

And in your other script:

symbol.nodes.code.timer = 10;
Z.every(1000,symbol.nodes.code.myTimer);

Happy coding! :smile:

Hey jvouillon. Thank you. The timer example you sent me works perfectly. :wink:
Now I am looking for a counter. I have it working by putting a code in every of the 10 questions if answer correctly then it adds a point and at the end it has to show how many questions were right. I just don’t know where I need to put things and one script only. So I understand the above. I will try that and instead of timer use the code that i am using in each screen to add a point. I will let you know if that works .
Thanks Again
Milenne

Oh, my mistake! I thought to wanted to call the timer from differents scripts… :slight_smile:

A counter is nothing more than a variable that you increment on each good answer… no need for a function.

Thanks. Yes, but I still want to increment only one variable and not having to use the same script where I declare a new variable every time.
The support team has sent me an email at the same time with some instructions very similar to yours. So I decided to have a go and it worked :wink:
So thank you both of you. :slight_smile:
incrementScore3_function.zpp (2.7 MB)

1 Like

Hello @digitalpopups , your dilemma is similar to mine. Did you figure out how to use functions for your quiz game? I would appreciate snippets of your code if you are willing to share.

If I remember right we used the code in the post above. (incrementScore3_function)
We had it set so you has 3 choices but it would move to the next question if you got it right or not.

If you give more details on what you need I maybe able to help more.

Steve

I have hit a brick wall spending hours of time trying to code the following for a 3D crossword puzzle with a custom-built UI keyboard. Could you help with this scenario?

//Player clicks WordPlane

//Font object associated with WordPlane is captured in a global variable – Export ClickedWord – ClickedWord also has a “Font” Object array representing each letter in the word – FontArray[] = [1AcrossLetter1, 1AcrossLetter2, 1AcrossLetter3…]

//Player clicks KeyboardLetterPlaneX (on a custom made keyboard)

//Letter associated with KeyboardLetterPlaneX is assigned as value to a global variable - Export KeyedLetter

//FontArray.0 associated with WordPlane = KeyedLetter. A counter increments through the letters in the Word until reaching the ClickedWordLength - 1

This is somewhat like the timer in the Archery Game except that the Timer is a singer object where the clock time is displayed on the font object. My ClickWord is a dynamic array that changes/resets each time a different WordPlane is clicked on. Part of my problem is that I’m trying to store “objects” as variables - ClickedWord, FontArray[0, 1, 2. …] I’ve explored using a dictionary instead of an array as well. Fonts don’t seem to work when stored as a variable, array or not. They seem to store, but when attempting to apply the KeyedLetter to an item in KeyedLetter[], it won’t work.