≡
Products
▼
Support
▼
Company
▼
Forum
Ambiera Forum
Discussions, Help and Support.
Create a new account
,
Search
, or Login:
Create reply in
Guest's scripts and plugins
Posted by:
(you are not logged in)
Enter the missing letter in: "?nternational"
(you are not logged in)
Text:
[quote][b]Guest[/b] wrote: So this time let's begin with the code: [code] // CopperCube action that prints the value of a variable to the console /* <action jsname="action_PrintVariable" description="Print variable"> <property name="VariableName" type="string" default="" /> <property name="isJSVar" type="bool" default="false" /> <property name="isToString" type="bool" default="false" /> <property name="isTypeOf" type="bool" default="false" /> </action> */ action_PrintVariable = function () { } action_PrintVariable.prototype.execute = function () { var value = ccbGetCopperCubeVariable(this.VariableName); if (this.isJSVar) { value = eval(this.VariableName); } if (this.isToString) { var newValue = value.toString(); if (this.isTypeOf) { print(typeof newValue); } else { print(newValue); } } else if (this.isTypeOf) { print(typeof value); } else { print(value); } } [/code] Save this action script as "action_PrintVariable.js" and follow the rest of the directions as mentioned already. In CC, you should see a new action: "Print variable." This action does a bit more than simply print the value of a CC variable. It also prints pure JavaScript variables. It prints their value types, and it also converts them to strings if need be. Why do we need all this? Generally, normal CC variables come in two types: strings and numbers via the action "Set or Change a Variable." Those print with no problems in the debug console; however, what if we want to use a boolean or object such as an array? If you print an object in CC, you get a return of "0.0,0.0,0.0." That's where this action script comes into play. Example: Open CC if you have not, add a "Before first drawing do something" behavior to the root scene node ("New 3D Scene1"), add two actions to that behavior: "Execute Java Script" and "Print variable." In the "Execute Java Script" behavior type: "var a = ["a", "b", "c"];" This defines an array, and in the "Print variable" action input "a" as the variable name (exclude quotation marks). Now test the app. You should see the result of "0" in the debug console. Why? This array is a JS variable, not a CC variable. So let's check the "isJSVar" option in the "Print variable" action and test the app again. "0.0, 0.0, 0.0" is your result. We know our array is an object, but let's prove it. In the "Print variable" action, check "isTypeOf" and test the app again. Result: "object." Now uncheck the "isTypeOf" option in the "Print variable" action and choose "isToString." Test the app again. Result: "a,b,c." One final thing: let's get the result of one of the array's indices. Uncheck "isToString" in the "Print variable" action. Type "a[0]' as the variable name. Check "isJSVar." Uncheck all the rest. Test the app. Result: "a", the first index of our array. All in all, this action is useful for displaying not only CC variables during runtime, but also JS variables, which is handy to have. These two actions (or some form of them) should be in everyone's toolkit, imo.[/quote]
Possible Codes
Feature
Code
Link
[url] www.example.com [/url]
Bold
[b]bold text[/b]
Image
[img]http://www.example.com/image.jpg[/img]
Quote
[quote]quoted text[/quote]
Code
[code]source code[/code]
Emoticons
Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact