Ambiera ForumDiscussions, Help and Support. |
|
[ 1 2 ] Page 1 of 2 |
|
|||||
|
Hi, i'm sorry if my question is stupid, but iI want to create an action when a button "A" is pressed then execute alert("hello world!"); but when I copy this into the "execute javascript" I get this error when i play the game and press "A": "ReferenceError: alert is not defined". I want to execute this javascript and when press "A" key, a little window is displayed, but this wouldn't happen :( Sorry for my bad english. |
||||
|
You must use the "print ()". |
||||
|
I think that is available for editor only ..... You can execute this command alert ("hello world") from scripting window available in the editor but can't execute in the final executable programme... |
||||
|
Thanks guys! So, it is impossible to generate a little window (like pop-up) during the game, when someone press a button? |
||||
|
You can use the command print (), or graphically, you can make appear or disappear a "2D Overlay" with the desired written. |
||||
|
Thank you. I'm sorry but i have another question: I want to count objects with the mouse (when click, count). I did it, but the problem is that you can count every object multiple times if you click on them multiple times. I would like to do that you can only do this once per object. For example if I have 3 objects (A, B and C) and I click on object A, then 2 times on object B and one time on C, my 2d overlay will display 4, and not 3, and that's a mistake. Now it's like this: "When clicked on this do something" action: "set or change a variable" --> add 1 to "varName". It works but I don't know how to disable multiple times counting on a object. I want to do that when you count an object, you can't count it again. Sorry for the inconvenience... |
||||
|
Hey bogo you can use if a varuable has value do something for example you have 4 objects and you dont want your click counter to get higher than value 4... Then you can simply use this action if a variable "varname" is more than 4, then set or change variable "varname" to 4.. Just increase the value 4, according to the objects present in ur scene... Hope that works... |
||||
|
Thank you just_in_case, that's a good idea, but it would be a "bug" for this game, because one of the goals would be to count the exact number of objects, but if you do this, someone could click 4 times on an object and win the goal... I tried the "restart behaviors of a scene node" action after a click (i tought that after this, it wouldn't count if you click again), but it didn't work |
||||
|
it is probably a bug, I sent a sample scene Niko I'm waiting for an answer. |
||||
|
That is not the bug...that behavious is working fine ... You can also hide the object after a click.... You have to create another action set variable" cliked _bject_1" = 1 and then assign the action if a variable cliked_object_1 has a value equal to 1 then set or change variable "click counter" add value +1.. And also have to use when mouse released up set variable clikced_object_1 = 0 You have to assign these actiona to all the objects present in ur scene... Variable cliked_object_1 should be changed according to the object names present in ur scene... Don't change the name of the variable click counter... Leave it same in all objects.. Hope you understand what am trying to say... Just create to instance of an object one in on mouse down and another is on mouse up... And add behaviour set or change variable ... One for click counter... Another one for tiggering click effect... |
||||
|
Wow just_in_case... you're a genius Thank you guys :) you resolved my problem |
||||
|
Me too I have a question about "execute javascript". I want to check if a variable has a "substring". example var myVariable = "hello buddy" var secondVariable = null if there is "buddy" in myVariable, than set the value of secondVariable to "buddy". Is this possible in coppercube? can you give me please the code? Thanks |
||||
|
Yes, use something like
|
||||
|
Thank you Erik! I tried your solution but it won't work. Script.1.ReferenceError.myVariable is not defined I have set ,,before first drawing do something'' and I have set variables myVariable and secondVariable. So I can't understand where i'm wrong? |
||||
|
theBikerJC, maybe you are new to JavaScript? You need to declare your variables, just as you wrote above in your example. The code snipped posted by erik above is just example code, it isn't the full code you would need, you would have to adjust it to your needs. |
[ 1 2 ] Page 1 of 2 |
|