e.other.text = scene.batterylev

About advanced scenes, and the Thyme scripting language used in Algodoo.

e.other.text = scene.batterylev

Postby minyman60 » Wed Oct 14, 2009 11:55 pm

hi everyone, im making a battery, its half decent upto now, but i cant get it to report the battery level on a box when this little spinning bar hits it, im getting error messages on my F11 screen.

something like, warning not a string. bla bla bla. Text bound to a bad type


Heres the scene for people to look at.

Rating: rated 5.1
Filesize: 65.92 kB
Comments: 3
Ratings: 3
download


Todo list: Get purple box showing scene.batterylev vairiable's data, which would display the power level for the battery.


also if anyone could help with linking the battery lev to the wheels autobreak that would be great, im assuming its somthing like

scene.batterylev >= 0 ?{false}:{true}

But i cant get it to stick on the wheels autobreak scripting section


Also my first scene using any type of If structure, that's why im messing around making a battery, just learned how to if =D
minyman60
 
Posts: 19
Joined: Wed Oct 14, 2009 11:39 pm

Re: e.other.text = scene.batterylev

Postby KarateBrot » Thu Oct 15, 2009 12:25 am

There are a few mistakes. i can see you didn't spell the variables the right way in your onCollide scripts. it has to be scene.MY.batterylev.
and e.other.powerlev and e.other.batterylev don't exist or did you define a variable for an object that's called powerlev and also batterylev in the scripting menu of that object? (if you want to call scene.my.batterylev you can't do that via e.other.batterylev)

Oh and if you want to display the value of scene.my.batterylev in the purple box you don't need a colliding object (the spinning little bar). in the script menu of the purple box in the "text =" field you have to type
Code: Select all
{"YouCanTypeWhateverYouWantHere" + scene.my.batterylev}

The { } brackets are telling algodoo that it's updating constantly so it knows that theres a variable and you don't need a colliding thing that updates it manually.
Last edited by KarateBrot on Thu Oct 15, 2009 12:32 am, edited 1 time in total.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: e.other.text = scene.batterylev

Postby minyman60 » Thu Oct 15, 2009 12:31 am

I did create two variables on the other item yes, I don't know if they work through save. But il have to start using scene.my from now on, should that fix my problem? even then, using the normal way, scene.batlev still works, it still reports a figure
minyman60
 
Posts: 19
Joined: Wed Oct 14, 2009 11:39 pm

Re: e.other.text = scene.batterylev

Postby KarateBrot » Thu Oct 15, 2009 12:35 am

yeah scene.batlev works but it only works because algodoo defines this variable automatically so after you press play you will have "scene.my.batterylev" and "scene.batlev" but those two are different variables and scene.batlev isn't a custom variable. i advise you to only use "scene.my.*" variables.
I try to figure out how your scene works and try to find all mistakes.

one question:
do you only want to make a battery that's discharging in this scene or is the car supposed to drive if the battery is pulled in?
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: e.other.text = scene.batterylev

Postby minyman60 » Thu Oct 15, 2009 12:42 am

I have just updated the scene based on your earlier suggestions, now the info is stored in the batterys Friction, for power ammount, and ControlerAcc for weather its a battery or not. since i didnt want to use binary...

Answer =D

Im not to sure, i was thinking that when its pluged in it would drive forward, later on i may upgrade it to something else.
minyman60
 
Posts: 19
Joined: Wed Oct 14, 2009 11:39 pm

Re: e.other.text = scene.batterylev

Postby KarateBrot » Thu Oct 15, 2009 12:47 am

ah btw... color values go up from 0 to 1 not 255. you did bright colors which are 255 times brighter than normal :D

now it works. if it's reaching the value 0 it's getting red and nothing happens anymore. but you don't need to make it complicated and store the batterylev into the objects friction value. just use scene.my.batterylev instead of e.other.friction and you can delete "scene.my.batterylev = e.other.Friction".
why complicated if it can be done more easily ;)
and to display scene.my.batterylev in the purple box delete the rotating little bar and type the code i posted above into the scripting menu of the purple box

ok, i just recognized that you already edited the text box :thumbup:
Last edited by KarateBrot on Thu Oct 15, 2009 12:58 am, edited 2 times in total.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: e.other.text = scene.batterylev

Postby minyman60 » Thu Oct 15, 2009 12:52 am

oh lol, Disclaimer, By downloading the scene you agree not to sue due to extra bright color's blinding your eyes.
minyman60
 
Posts: 19
Joined: Wed Oct 14, 2009 11:39 pm

Re: e.other.text = scene.batterylev

Postby KarateBrot » Thu Oct 15, 2009 12:55 am

minyman60 wrote:oh lol, Disclaimer, By downloading the scene you agree not to sue due to extra bright color's blinding your eyes.


:D lol
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: e.other.text = scene.batterylev

Postby minyman60 » Thu Oct 15, 2009 12:59 am

KarateBrot wrote:. but you don't need to make it complicated and store the batterylev into the objects friction value. just use scene.my.batterylev instead of e.other.friction and you can delete "scene.my.batterylev = e.other.Friction".


but now it supports multipul batterys, well. with one or two tweeks
minyman60
 
Posts: 19
Joined: Wed Oct 14, 2009 11:39 pm

Re: e.other.text = scene.batterylev

Postby KarateBrot » Thu Oct 15, 2009 1:09 am

ok that's an argument.^^
but using the friction value can cause problems sometimes. for example if you want to pull the battery in it can be difficult becasue the fiction is freaking high. doesn't seem to be a big problem here but it could be a problem anywhere else in one of your future projects if you want to store values in object variables that change the properties of your object. so you could define a new variable in the scripting menu.
on the bottom of the scripting menu you can see an empty line where you can type anything. type something like charge := 200 and you will see a new entry in your scripting menu that's called "charge". then just replace all your "e.other.friction" with "e.other.charge". that's pretty cool and you doN't need to change the object properties like friction or density or something.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: e.other.text = scene.batterylev

Postby minyman60 » Thu Oct 15, 2009 1:20 am

Do you know how i would use {scene.my.batterylev > 0 ?{1.5}:{0}} on motor speed, its not working, it keeps vanishing every time i go off the hinge script menu
minyman60
 
Posts: 19
Joined: Wed Oct 14, 2009 11:39 pm

Re: e.other.text = scene.batterylev

Postby KarateBrot » Thu Oct 15, 2009 1:25 am

did you press enter after typing it in? if you don't do that it will just vanish.
the code you want to enter is correct and works. i tested it so it can't be a problem with the code.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: e.other.text = scene.batterylev

Postby minyman60 » Thu Oct 15, 2009 1:29 am

yeah, i pressed enter a few times. I dunno, il keep trying, il copy it in now...

Edit, Still nothing, it just wont stick

I do have it sending a string through in the 1.4, instead of numbers, Maybe its erasing the code somehow...
minyman60
 
Posts: 19
Joined: Wed Oct 14, 2009 11:39 pm

Re: e.other.text = scene.batterylev

Postby KarateBrot » Thu Oct 15, 2009 1:50 am

ok now i know why it's not working. you said it's now a string and that's the problem.

first to mention:
a string has to be entered a bit different from other variable types so that algodoo knows that it's a string. the string variable must contain " " around it.
for example: scene.my.batterylev = "Whatever"

And because it's a string your motorspeed code has to look like this:
{scene.my.batterylev > "0" ?{1.5}:{0}}
If you don't type " " around the 0 it will vanish because it's not a string and algodoo doesn't know what to do with it.

So in you scene.my.batterylev you have to delete your "no data available" and replace it with a number or you have to get another idea otherwise your motorSpeed code won't work.

I've got an idea:
ok, first you have to make your scene.my.batterylev a number again.
then in the oncollide of your bar that hits the battery instead of using
e.other.ControllerAcc == 11 ? {scene.my.batterylev = "No Data Available"} : {}
you can define a new scene.my. variable that contains 1 or 0 (1 and 0 because true / false doesn't seem to work here oO) and replace it with "scene.my.batterylev = "No Data Available"" for example
e.other.ControllerAcc == 11 ? {scene.my.dataAvailable = 0} : {}

and in the purple text box you have to enter this code in your text field:
Code: Select all
{scene.my.DataAvailable == 1 ? {"Power level - " + scene.my.batterylev} : {"No Data Available"}}
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: e.other.text = scene.batterylev

Postby Sniperkasa » Thu Oct 15, 2009 9:55 am

Try this
{scene.my.batterylev >= 0 ?{1.5}:{0}}
Notice the -> = <-
If you have a question, have a dollar and call somebody that cares.
No really just PM me if you have a problem :)
User avatar
Sniperkasa
 
Posts: 493
Joined: Tue Sep 01, 2009 5:34 pm
Location: The bottom of a lake.

Re: e.other.text = scene.batterylev

Postby minyman60 » Thu Oct 15, 2009 2:54 pm

Great now it works. Thanks for all your help, I can post this in scenes now that its all good, and see if anyone can use it in anything cool.

Scene has been updated to finished result. Should be working now.
minyman60
 
Posts: 19
Joined: Wed Oct 14, 2009 11:39 pm

Re: e.other.text = scene.batterylev

Postby KarateBrot » Thu Oct 15, 2009 10:37 pm

cool :clap:
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: e.other.text = scene.batterylev

Postby minyman60 » Thu Oct 15, 2009 11:08 pm

theres still more i can do with it actualy, so im going to refine it a bit more. But its in scenes now.
minyman60
 
Posts: 19
Joined: Wed Oct 14, 2009 11:39 pm

Re: e.other.text = scene.batterylev

Postby minyman60 » Sun Oct 18, 2009 10:15 pm

Ok well now i have another text based problem. so i thaught i would post it here... since this was started for one text prob...

Ok so, Im trying to get a box to give a readout of a battery. But, if the battery has more than 100 power i just want it to display Battery One: 100, Otherwise i want it to display the normal value, like Battery One : 67 or something like that.

heres what i have, unfortunatly its not working. and i have no idea why, Im not getting any warnings on F11 screen as well.
Code: Select all
{ "Battery One: " + scene.my.chargestatEN >= 100 ?{"100"}:{scene.my.chargestatEN}}
minyman60
 
Posts: 19
Joined: Wed Oct 14, 2009 11:39 pm

Re: e.other.text = scene.batterylev

Postby KarateBrot » Mon Oct 19, 2009 12:09 am

everything's alright you just need to place two nowmal brackets so that algodoo knows that everything belongs to each other after the +. otherwise only scene.my.chargestatEN belongs to the + and the rest will cause an error

Code: Select all
{ "Battery One: " + (scene.my.chargestatEN >= 100 ? {"100"} : {scene.my.chargestatEN}) }
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: e.other.text = scene.batterylev

Postby minyman60 » Mon Oct 19, 2009 1:14 am

Ahhh, Ok that makes sence, thanks mate
minyman60
 
Posts: 19
Joined: Wed Oct 14, 2009 11:39 pm

Re: e.other.text = scene.batterylev

Postby KarateBrot » Mon Oct 19, 2009 1:53 am

no problem :thumbup:
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: e.other.text = scene.batterylev

Postby Sniperkasa » Mon Oct 19, 2009 4:01 pm

Was it the >= that was the problem, just btw?
If you have a question, have a dollar and call somebody that cares.
No really just PM me if you have a problem :)
User avatar
Sniperkasa
 
Posts: 493
Joined: Tue Sep 01, 2009 5:34 pm
Location: The bottom of a lake.

Re: e.other.text = scene.batterylev

Postby KarateBrot » Mon Oct 19, 2009 4:35 pm

no, it was just an error because of brackets. there had to be () brackets otherwise algodoo doesn't know what to do with the whole thing.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: e.other.text = scene.batterylev

Postby minyman60 » Mon Oct 19, 2009 11:03 pm

Karate is right, I think the >= is right
minyman60
 
Posts: 19
Joined: Wed Oct 14, 2009 11:39 pm

Next

Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 7 guests