paint-like help

Blitz3D Forums/Blitz3D Beginners Area/paint-like help

olo(Posted 2008) [#1]
Hi all,
i need help with making a paint-like program where you paint parts of an abject. I've got the code that colors a part when you hold down a key but this isnt what i would like.
There are quite a few objects that will be painted and it will be hard to remember all the keys :(

What i would like to know is how to divide my code into pieces and be able to do this:

when i press a certain key i will be able to color the part that corresponds to that key using the same keys that color the other object...confusing??
Simplified:

1) i will use keys 1 to 6 to change the color(e.g. 2 will rise the red value and 1 will decrease it, 4 will rise green value and 3 will decrease it, etc.)

2) Lets say there are three parts; a,b,c

3) When i press 8 then i will only be able to change the color of part a using keys 1 to 6 as above
When i press 9 i will only be able to change the color of part b using the same keys, 1 to 6
Same applies for part c

any ideas on how to do this, all welcome, and is it possible?


olo(Posted 2008) [#2]
Am i being unclear about what i am asking about?
if so, please do tell me


Pirate(Posted 2008) [#3]
most of the time it is best to post some code that shows the part of the program you are having trouble with...this is the best way to get help...


olo(Posted 2008) [#4]
;changing the color of the objects
If KeyDown( 2 )=True And red#>0 Then red#=red#-1
	If KeyDown( 3 )=True And red#<255 Then red#=red#+1
	If KeyDown( 4 )=True And green#>0 Then green#=green#-1
	If KeyDown( 5 )=True And green#<255 Then green#=green#+1
	If KeyDown( 6 )=True And blue#>0 Then blue#=blue#-1
	If KeyDown( 7 )=True And blue#<255 Then blue#=blue#+1

EntityColor car, red#, green#, blue#
EntityColor bws, red#, green#, blue#
EntityColor fws, red#, green#, blue#
EntityColor middle, red#, green#, blue#


Above it is not so much of a problem, it is basically what i want except that when i add other objects, that will be colored separately, i will be using many more keys. What i am asking is if i can only stick to these 6 keys and choose the part i want to color.

Right now, i have no idea on how to separate the parts and allow the player to choose which part he wants to customize (color)

Here are the steps that the player will folow:
1) first pick the object you want to color

2)then change the color using only a few keys (the six i mentioned)

**The only object that will be colored after these steps will be the one that was picked in the beginning**

oh and thanks for posting, pirate, quite new here


olo(Posted 2008) [#5]
this is an example (doesnt work)of what i am trying to do here:
;coloring the first object
If KeyDown(2) Then 


	If KeyDown( 2 )=True And red#>0 Then red#=red#-1
	If KeyDown( 3 )=True And red#<255 Then red#=red#+1
	If KeyDown( 4 )=True And green#>0 Then green#=green#-1
	If KeyDown( 5 )=True And green#<255 Then green#=green#+1
	If KeyDown( 6 )=True And blue#>0 Then blue#=blue#-1
	If KeyDown( 7 )=True And blue#<255 Then blue#=blue#+1

EntityColor cube, red#, green#, blue#

;coloring the second object
If KeyDown(3) Then


If KeyDown( 2 )=True And red#>0 Then red#=red#-1
	If KeyDown( 3 )=True And red#<255 Then red#=red#+1
	If KeyDown( 4 )=True And green#>0 Then green#=green#-1
	If KeyDown( 5 )=True And green#<255 Then green#=green#+1
	If KeyDown( 6 )=True And blue#>0 Then blue#=blue#-1
	If KeyDown( 7 )=True And blue#<255 Then blue#=blue#+1

EntityColor sphere, red#, green#, blue#

;coloring the third object
If KeyDown(3) Then

If KeyDown( 2 )=True And red#>0 Then red#=red#-1
	If KeyDown( 3 )=True And red#<255 Then red#=red#+1
	If KeyDown( 4 )=True And green#>0 Then green#=green#-1
	If KeyDown( 5 )=True And green#<255 Then green#=green#+1
	If KeyDown( 6 )=True And blue#>0 Then blue#=blue#-1
	If KeyDown( 7 )=True And blue#<255 Then blue#=blue#+1

EntityColor cone, red#, green#, blue#


does anyone know? even if you dont, tell me..


Warner(Posted 2008) [#6]
There is no single solution for this problem. In fact, you could solve it in several ways.
First, you'll need to be able to select the object you want to color. For that, you could make a variable that stores the handle to the object:
active = car

repeat

   if keyhit(2) active = car
   if keyhit(3) active = bws
   if keyhit(4) active = fws
   if keyhit(5) active = middle

   entitycolor active, red, green, blue

..


Then, you'll need to store the red/green/blue for each object. For that, an array might be usable:



olo(Posted 2008) [#7]
trying it out now, i will let you know when i encounter problems or success (hopefully)

Thanks


olo(Posted 2008) [#8]
I am not sure what i am supposed to do with the first part. I do not understand what it means. Please could you explain. and also what is sel standing for, i know it is a variable but what of?


Warner(Posted 2008) [#9]
The line:
 entitycolor active, red, green, blue

changes the color of the object that is refered to with the 'active' variable.
So if you say:
active = car

then the line will change the color of the car.
However, after you say:
active = bws
the line will change the color of bws.

The second part is a bit harder to explain. It deals with arrays, which are defined with a Dim (=dimension?) statement.
Dim allows for multiple variables to be refered to, using a number as an index.
So, if you create an array:
Dim x(10)

Then, after that, you can use x(0), x(1), x(2) .. etc x(10).
In this matter, "sel" is a number that is filled in between the brackets. So, if sel = 1, then the line
entitycolor active, red(sel), green(sel), blue(sel)
will become
entitycolor active, red(1), green(1), blue(1)
And if sel = 2 then the line will be
entitycolor active, red(2), green(2), blue(2)

Maybe the best explanation will be a working example:


olo(Posted 2008) [#10]
YEEEEY!!

thanks so much man, i finally got it.

thank you for doing all this for me :D


olo(Posted 2008) [#11]
i just have one more question... :/
Everything works, i would just like to know how i can color more than one object. I have a few objects put together and i was wondering how i could make them one item, so that when i changed the color of lets say A.. B and C will change with it.
Thanks again


Warner(Posted 2008) [#12]
Maybe you could use AddMesh to merge the objects together ?


olo(Posted 2008) [#13]
i have never used this command before.
is it simply?:
Addmesh object1, object2


if not please correct me


Warner(Posted 2008) [#14]
Yes, but you should also FreeMesh object1 after adding it to object 2.


olo(Posted 2008) [#15]
FreeMesh doesnt exist... i wrote:

AddMesh object1, object2
FreeMesh object1

but it doesnt work, do you know why?


Warner(Posted 2008) [#16]
Ow .. my bad .. FreeEntity :D


olo(Posted 2008) [#17]
ok, but that makes the object1 dissapear and nothing else. :(

here is my code:
;array of colors
Dim red(5)
Dim green(5)
Dim blue(5)

;inizialize 6 seperate colors
For i=0 To 5
	
	red(i)=activepart
	green(i)=activepart
	blue(i)=activepart
	
Next 

AddMesh fws, car
FreeEntity fws

;Select Object (part)
activepart = car

;select color 0 -> red 0  green 0  blue 0
selection = 0

Repeat


;game loop
While Not KeyDown(1)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;use keys 1-6 to change part
	If KeyHit(2) Then activepart = car: selection = 0
	
	
	If KeyHit(3) Then activepart = bb: selection = 1
	If KeyHit(3) Then activepart = fb: selection = 1

	
	If KeyHit(4) Then activepart = stripe1: selection = 2
	If KeyHit(4) Then activepart = stripe2: selection = 2
	If KeyHit(4) Then activepart = stripe3: selection = 2
	If KeyHit(4) Then activepart = stripe4: selection = 2
	If KeyHit(4) Then activepart = stripe5: selection = 2
	If KeyHit(4) Then activepart = stripe6: selection = 2
	
	
	If KeyHit(5) Then activepart = cube: selection = 3
	
	
	If KeyHit(6) Then activepart = windf: selection = 4
	If KeyHit(6) Then activepart = windb: selection = 4
	If KeyHit(6) Then activepart = sidew: selection = 4
	If KeyHit(6) Then activepart = sidew2: selection = 4
	
;get color of current object
	r = red(selection)
	g = green(selection)
	b = blue(selection)
	
;apply color to current object
	EntityColor activepart, r, g, b
	
;use cursor keys to change color
	If KeyDown(203) Then r = r - 10
	If KeyDown(205) Then r = r + 10
	If KeyDown(200) Then g = g - 10
	If KeyDown(208) Then g = g + 10
	
;put r,g,b back into array
	red(selection) = r
	green(selection) = g
	blue(selection) = b



anything i am doing wrong which is causing it to not work?

Please help


olo(Posted 2008) [#18]
please, does anyone know? :0(


Warner(Posted 2008) [#19]
I think it is this part:
For i=0 To 5
	
	red(i)=activepart
	green(i)=activepart
	blue(i)=activepart
	
Next 

It sets the colors to black, since the variable 'activepart' is zero at the start of the program. Instead, it should be 255. So, instead, set red(), green() and blue() to 255.
For i=0 To 5
	
	red(i)=255
	green(i)=255
	blue(i)=255
	
Next 


Then another thing:
	If KeyHit(4) Then activepart = stripe1: selection = 2
	If KeyHit(4) Then activepart = stripe2: selection = 2
	If KeyHit(4) Then activepart = stripe3: selection = 2
	If KeyHit(4) Then activepart = stripe4: selection = 2
	If KeyHit(4) Then activepart = stripe5: selection = 2
	If KeyHit(4) Then activepart = stripe6: selection = 2

From this code, only the first line will execute. After reading KeyHit() once, it is reset to zero again, until the key is pressed again. Instead, use only one "If KeyHit()" for the entire block:
If KeyHit(4) Then
  activepart = stripe1: selection = 2
  activepart = stripe2: selection = 2
  activepart = stripe3: selection = 2
  activepart = stripe4: selection = 2
End If

And .. you can only store one object in 'activepart'. So after saying:
activepart = stripe1
activepart = stripe2
activepart = stripe3
activepart = stripe4

'activepart' will be set to 'stripe4' only. The first three lines are redundant.