Displaying variable with text

Im not an expert at javascript but cant you just write the code as:
textName.setText(score);?

because the text would write whatever is inside the variable, strings and all.

thank you so much! I am very new to JS so this helped me alot!

Im having more issues now. I want everytime I hover on a circle it to add 1 to a variable.
So I put all the var score = 0; scoretext.setText(score); on the mousehover atribute and put under that var score = score + 1; but that is giving me errors. I am very confused.

How would I go about making it so that everytime I hover on this button it adds 1 to the score variable?

I dont think you needed to use var again once you made a variable (unless you’re making an entirely different variable named Score, since Javascript is CaseSensitive!), you could just call the variable score again just by typing it:

score = score + 1

This is my last issue for the night. I have my initial var score = 0; set on the scene load reference. Then I have the scoretext.setText(score); on the update reference. I dont think this is necessary but I have it there. Then I have the score = score + 1 under mousehover on the actual button. Everything else has not been on the button. But it is saying the score is not defined. Do I have to put everything on one reference? How do I get around this and are there any issues with the code?

I’m also not very good at coding, I apologize. I told you all that I know in my current knowledge of javascript (or scripting in general). I did comment that I’m not an expert at javascript, but I tried.

Out of curiosity, may I see the project. I wanted to see how you tried to do it and see if I can help you out any further (or maybe learn along with you, as weird as that sounds).

Klicker12-6-2020_1-34-12AM.wick (199.6 KB) I have a thread on my profile about this game.
Go to scene 50 to see what Im talking about.

*this version of WickEditor we’re using is 1.18

Klicker12-6-2020_4-12-02PM (KringlePrinkle’s Edit).wick (199.9 KB)
Heeyo I discovered something~!

Apparently when making variables, you have to parent it to an object for it to work (i think?)
(eg: project.magic sets the variable magic to the project! man.power sets the variable power to the clip man.)

I thought i could set project.score as a variable Score for easier use but…
image

And I searched up about variables and apparently they can only be global if they’re not used inside a function.

(have you guessed why it doesn't recognize the variable score?)

*this is just an educated guess based on what i just learned about variables and wickeditor

Because the events used are ALL functions, making all variables local for each function.
this is (i believe) the reason why the variables are not called. since they’re not global variables, we have to write variables as (clip name/project).(variable name) for you to be able to get the variable stored in the object.

I might have to learn javascript soon, but for now if anyone else knows a simpler way to call variables in wickeditor, do reply in this thread.

thank you!

1 Like

yes you need to put the variable into something like a clip or the project so you can access the variable outside of the script it was defined in

also you can just write score++ or score += 1 instead of score = score + 1, they do exactly the same thing but it takes less time to write it

about "(have you guessed why it doesn't recognize the variable score?)"

also @KringlePrinkles, I think they use eval to run the scripts instead of creating a function, otherwise it wouldn’t error when I write “return” outside a function in a script. I think the reason the variables stay in the scope of the script is because the eval call is inside a different function. Try this:

function evalScript(script) {
  eval(script)
}

evalScript("var a = 3; alert(\"Eval done \")")
alert(a)

It will error on the last line. I think this is kinda what Wick Editor does to run scripts

yeah right now the box goes always to the top left i’ll try to fix

okay I was also having issues with the random position aspect of it.

I had wrote something like math.random. I forgot because my pc crashed last night around 2am so i dont have the wick file.

Anyways I remember it glitching out and going to the same potion each time. Anyway to make it so that on hover it would go to a random x,y?

I recommend using the built in random number command, aka: random.integer(min,max)

I made some script changes, and hopefully this helps:
Klicker12-6-2020_1-30-51PM.wick (204.4 KB)

thank you. i am download it as a write this. will write back in 1 - 5 mins

would there be a way to make it so that they would not overlap?

like if object is over object then goto random else stay put ?
and then it would just find a new location each time if it was overlapping?

// keep relocating circle2 until it no longer touches circle1
while(circle1.hitTest(circle2)) {
// place circle2 in a different location
}

what object do i put it on?
do i put it on the circle or on somthing else?

put it on something else i think.

ill put it on update

i think you should run that code when the circle moves