OnCollide Help (please help me)

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

OnCollide Help (please help me)

Postby FlareonTheFlareon » Wed Apr 13, 2016 6:28 am

I'm having a issue with OnCollide scripting. So let's just get straight to the point:

Okay, so I'm making a marble race with all kinds of colors, like shown here: http://orig11.deviantart.net/84a3/f/2016/103/9/6/screen_shot_2016_04_12_at_5_52_30_pm_by_flareontheflareon-d9yuq01.png

These marbles are going through a eliminater that looks something like this, the black rectangles inside are supposed to determine what position the marble finished that legs:http://orig07.deviantart.net/ae57/f/2016/103/f/1/screen_shot_2016_04_12_at_5_57_01_pm_by_flareontheflareon-d9yuqda.png

Now these rectangles have a code and the code is posted here:
Code: Select all
(e)=>{
    e.other.pos = scene.my.tpNo7;
    e.other.vel = [0, 0];
    e.this.color = e.other.color;
    e.this.texture = e.other.texture;
    e.this.collideSet = 0
}

This code practically colors the rectangle to fit the color of marble hitting it.

So what's my issue? Well, I want these marbles to show text of the name of their color as shown in the first link. So like, when a marble hits the rectangle, it displays the name of their color. However, I already know it's impossible to name colors since colors are kind of biased by name, so I tried to use materialName and named all 84 marbles their separate color name. HOWEVER, I don't know HOW to code this properly, and I pretty much tried everything I could to make it work, but I couldn't get it to work at all. In addition, if the such a script it possible, I want to know how to change the color of this text for darker colors like Black. But again, I do not know how.

So I'm wondering if you guys could help me out in finding a way to script this. That whenever that a different colored marble hits the rectangle, it displays the text of the name of color in the rectangle itself. In addition, a way to change the color of the text for darker colors, as well. If the process I claimed earlier is impossible, then I love to see you guys think of a way to make this happen.

Here's the file if you want to try to script it out:
Rating: rated 5
Filesize: 57.74 kB
Comments: 3
Ratings: 1
download
Hi. I'm FlareTheFlare, I'm a dude who draws random things on my deviantArt, watches YouTube stuff, & listens to EDM music. So apparently I do stuff in Algodoo too? Mainly it's because I'm interested in creating Marble Races, myself.

Here's my Youtube thing: https://www.youtube.com/channel/UCm5iZH ... RFMZh9yXhA
And my dA thing: http://flareontheflareon.deviantart.com/
User avatar
FlareonTheFlareon
 
Posts: 7
Joined: Sat Mar 26, 2016 9:58 am

Re: OnCollide Help (please help me)

Postby Kilinich » Wed Apr 13, 2016 11:14 am

Code: Select all
scene.my.nameOfColor = [[[1,0,0,1],"Red"],[[0,1,0,1],"Green"],[[0,0,1,1],"Blue"]];
scene.my.getColorName = (color) => {
  cName := "Unknown";
  for(string.length(scene.my.nameOfColor), (i) => {
    color == scene.my.nameOfColor(i)(0) ?  {cName = scene.my.nameOfColor(i)(1)} : {};
  });
  cName;
}


You got the idea - fill scene.my.nameOfColor with [color, "name"] pairs and use like this:
> Scene.my.getColorName([0,1,0,1])
Green
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: OnCollide Help (please help me)

Postby FlareonTheFlareon » Wed Apr 13, 2016 6:47 pm

Thank you for the code! But I have other questions:

1. Paste this code into the rectangles, correct?
2. Do I have to copy & paste the code 84 times, for each marble in order for it to work, or do I separate each of the colors with a comma by the brackets, as shown: "scene.my.nameOfColor = [[[1,0,0,1],"Red"],[[0,1,0,1],"Green"],[[0,0,1,1],"Blue"]]"
3. Does this also change the color of the text with darker colors? Cause of course, black text over a black rectangle doesn't really make sense, right?
4. The code I pasted in number 2, the "[1,0,0,1]" bracketed are the HSV values, right?

(I'm so sorry for asking so much questions, I'm a beginner with Scripting and I'm trying to get the hang of things.)
Hi. I'm FlareTheFlare, I'm a dude who draws random things on my deviantArt, watches YouTube stuff, & listens to EDM music. So apparently I do stuff in Algodoo too? Mainly it's because I'm interested in creating Marble Races, myself.

Here's my Youtube thing: https://www.youtube.com/channel/UCm5iZH ... RFMZh9yXhA
And my dA thing: http://flareontheflareon.deviantart.com/
User avatar
FlareonTheFlareon
 
Posts: 7
Joined: Sat Mar 26, 2016 9:58 am

Re: OnCollide Help (please help me)

Postby Kilinich » Wed Apr 13, 2016 10:28 pm

FlareonTheFlareon wrote:Thank you for the code! But I have other questions:

1. Paste this code into the rectangles, correct?
2. Do I have to copy & paste the code 84 times, for each marble in order for it to work, or do I separate each of the colors with a comma by the brackets, as shown: "scene.my.nameOfColor = [[[1,0,0,1],"Red"],[[0,1,0,1],"Green"],[[0,0,1,1],"Blue"]]"
3. Does this also change the color of the text with darker colors? Cause of course, black text over a black rectangle doesn't really make sense, right?
4. The code I pasted in number 2, the "[1,0,0,1]" bracketed are the HSV values, right?

(I'm so sorry for asking so much questions, I'm a beginner with Scripting and I'm trying to get the hang of things.)


1) No, you should paste in in console
2) No, I'd rather you call that function from one object that marble hit
3) No, it dont change anything, it returns name of color if it is so
4) No, it's [R,G,B, Alpha]

I've got better idea! :idea:
Just add _name variable to every manrbel and display it where you need to. :thumbup:
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: OnCollide Help (please help me)

Postby FlareonTheFlareon » Thu Apr 14, 2016 12:47 am

Huh? "Add_Name"?

I never heard of that before... I'd like an explanation of that please, cause I got no clue if that's for the console or the OnCollide box. I also wonder how you input it.

Well... Is there a way that I can change the color text when the marble hits the rectangle? Like, I want the text to be white when a Black marble hits a rectangle...

2) No, I'd rather you call that function from one object that marble hit

I also love an explanation for what do you mean by this... ^_^'

As you can see, I am still VERRRRY confused about this. XP
Hi. I'm FlareTheFlare, I'm a dude who draws random things on my deviantArt, watches YouTube stuff, & listens to EDM music. So apparently I do stuff in Algodoo too? Mainly it's because I'm interested in creating Marble Races, myself.

Here's my Youtube thing: https://www.youtube.com/channel/UCm5iZH ... RFMZh9yXhA
And my dA thing: http://flareontheflareon.deviantart.com/
User avatar
FlareonTheFlareon
 
Posts: 7
Joined: Sat Mar 26, 2016 9:58 am

Re: OnCollide Help (please help me)

Postby Kilinich » Thu Apr 14, 2016 9:39 am

In script menu window of any entity you could add some variables.
Just type

var := 1;

and it will add property to list.

Custom variables starting with _ char will be serialized and saved with scene.
Try to add _name := "Test"
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: OnCollide Help (please help me)

Postby FlareonTheFlareon » Thu Apr 14, 2016 6:12 pm

Alright, so if I add_name variable for every marble, what do I do next? Of course anything placed in consoles will obviously need to be placed in the script menu.

I'd really like it if you made a simulation of the problem, so I can getting easier explanation, rather just from text. ^^
Hi. I'm FlareTheFlare, I'm a dude who draws random things on my deviantArt, watches YouTube stuff, & listens to EDM music. So apparently I do stuff in Algodoo too? Mainly it's because I'm interested in creating Marble Races, myself.

Here's my Youtube thing: https://www.youtube.com/channel/UCm5iZH ... RFMZh9yXhA
And my dA thing: http://flareontheflareon.deviantart.com/
User avatar
FlareonTheFlareon
 
Posts: 7
Joined: Sat Mar 26, 2016 9:58 am

Re: OnCollide Help (please help me)

Postby icrls984 » Fri Apr 15, 2016 7:05 am

I am relatively new to scripting, and don't understand a lot of the code as well as I would like, but could you not just do some "script" on the rectangle oncollides, that change the text to be equal to the other entity's material name? :?
http://imgur.com/bNWmKsc
If it works well enough, then all you might have to do is fix the font size.
I don't know much about scripting, but I hoped this simplistic answer helped! :)
If I had seen that code Kilinich created when I was much more inept in this scripting stuff, I would have been even more confused than you!
Edit: I was just thinking, maybe the font color could be chosen by taking the marble color and negating it? A long time ago, a nice person shared this small piece of script inverting color "e.other.color = [1,1,1,2] - e.other.color", replace the variable(?) being changed with e.this.textColor. Or by turning the marble color into HSV and checking if the V is larger than 0.5, in which case the textColor turns black?
http://i.imgur.com/Ug4b977.png
.
User avatar
icrls984
 
Posts: 80
Joined: Thu Jun 13, 2013 6:33 am

Re: OnCollide Help (please help me)

Postby FlareonTheFlareon » Fri Apr 15, 2016 7:42 am

icrls984 wrote:I am relatively new to scripting, and don't understand a lot of the code as well as I would like, but could you not just do some "script" on the rectangle oncollides, that change the text to be equal to the other entity's material name? :?
http://imgur.com/bNWmKsc
If it works well enough, then all you might have to do is fix the font size.
I don't know much about scripting, but I hoped this simplistic answer helped! :)
If I had seen that code Kilinich created when I was much more inept in this scripting stuff, I would have been even more confused than you!
Edit: I was just thinking, maybe the font color could be chosen by taking the marble color and negating it? A long time ago, a nice person shared this small piece of script inverting color "e.other.color = [1,1,1,2] - e.other.color", replace the variable(?) being changed with e.this.textColor. Or by turning the marble color into HSV and checking if the V is larger than 0.5, in which case the textColor turns black?
http://i.imgur.com/Ug4b977.png


Holy crud, it actually worked! Thank you! But what do you mean by "V" in HSV? You mean Value, right? XD
Hi. I'm FlareTheFlare, I'm a dude who draws random things on my deviantArt, watches YouTube stuff, & listens to EDM music. So apparently I do stuff in Algodoo too? Mainly it's because I'm interested in creating Marble Races, myself.

Here's my Youtube thing: https://www.youtube.com/channel/UCm5iZH ... RFMZh9yXhA
And my dA thing: http://flareontheflareon.deviantart.com/
User avatar
FlareonTheFlareon
 
Posts: 7
Joined: Sat Mar 26, 2016 9:58 am

Re: OnCollide Help (please help me)

Postby icrls984 » Sat Apr 16, 2016 5:42 am

Yup! V is the Value. You're welcome, it didn't take much time for me to try to get it to work :)
Keep scripting! :thumbup:
Personally, I always try to find a simpler way to solve the problem if I can, rather than making long complicated scripts.
.
User avatar
icrls984
 
Posts: 80
Joined: Thu Jun 13, 2013 6:33 am


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 28 guests

cron