Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Game programming

Opacity Override Issue[Solved]  [SOLVED]

All about the StoneScript

Opacity Override Issue[Solved]

Postby RedQueen » 09 May 2012, 11:36

I have tried for the past few days to see where the code is going wrong on changing the opacity of my model materials I kept going back to the documentation on overriding materials everything looks right and it was working for a moment but now it doesn't even override the opacity anymore. Here is a vid of me stepping through in debug mode and even though it runs the command its still not doing it. I am absolutely stumped and can't figure out why it stopped working.

http://www.youtube.com/watch?v=3KhjegWxOy4

**NOTE** OKAY if you change the setting to 1080p you can read the code it is stepping through
Last edited by RedQueen on 19 May 2012, 11:56, edited 1 time in total.
RedQueen
Platinum Boarder
Platinum Boarder
 
Posts: 328

Re: Opacity Override Issue

Postby giggsy » 09 May 2012, 12:28

Hi,

scripting values sometimes vary from the values in the editor (1.0 vs. 255) ... "The opacity value lies between 0.0 and 1.0."
http://www.stonetrip.com/developer/doc/api/shape-overrideMeshSubsetMaterialOpacity
User avatar
giggsy
Platinum Boarder
Platinum Boarder
 
Posts: 1101
Location: Austria

Re: Opacity Override Issue

Postby RedQueen » 09 May 2012, 13:09

That was what I was trying to figure out if the nOpacity was set to 0 if that meant it was suppose to be invisible or vice verse. But the weird thing is it was working at first and then it stopped and hasn't since then.
RedQueen
Platinum Boarder
Platinum Boarder
 
Posts: 328

Re: Opacity Override Issue

Postby RedQueen » 14 May 2012, 01:35

I am still stump to this. I have a function ActivateStone that will make it invisible and play a sound

Code: Select all
function DemonBoard.ActivateStone ( )
  local activeColor=this.var_Color()
  log.error ( "Active color:",activeColor )
   --lets find the object to turn on the particles
   if(activeColor=="blue")then
    log.error ( this.getObject ( ) )
    shape.overrideMeshSubsetMaterialOpacity (this.getObject ( ),3,0,5 )
    --lets play sound
    sound.play ( this.getObject ( ),0,1,false,1 )
   end   
    if(activeColor=="red")then
log.error ( this.getObject ( ) )
    shape.overrideMeshSubsetMaterialOpacity (this.getObject ( ),2,0,5 )
    sound.play ( this.getObject(),1,1,false,1 )
    end
    if(activeColor=="brown")then
      log.error ( this.getObject ( ) )
        shape.overrideMeshSubsetMaterialOpacity (this.getObject ( ),0,0,5)
        sound.play ( this.getObject ( ),2,1,false,1 )
    end
   
    if(activeColor=="green")then
    log.error ( this.getObject ( ) )
        shape.overrideMeshSubsetMaterialOpacity (this.getObject ( ),1,0,5 )
       
        sound.play ( this.getObject ( ),3,1,false,1 )
    end   
--------------------------------------------------------------------------------
end


This works fine and does what it suppose to do when I don't access the DeActivateStone function which is this-
Code: Select all
function DemonBoard.DeActivateStone ( )
--------------------------------------------------------------------------------
   local activeColor=this.var_Color()
   --let's turn the particle off
    if(this.stone_Active ( ))then
        if(activeColor=="blue")then
        --make shape visible again     
         shape.overrideMeshSubsetMaterialOpacity (this.getObject ( ),3,1,50)
         --shape.
         sound.stop ( this.getObject ( ),0 )
         
        end   
        if(activeColor=="red")then
         shape.overrideMeshSubsetMaterialOpacity (this.getObject ( ),2,1,50)
          sound.stop ( this.getObject ( ),1 )
        end
        if(activeColor=="brown")then
         shape.overrideMeshSubsetMaterialOpacity (this.getObject ( ),0,1,50)
         sound.stop(this.getObject ( ),2)
        end
        if(activeColor=="green")then
         shape.overrideMeshSubsetMaterialOpacity (this.getObject ( ),1,1,50)
         sound.stop ( this.getObject(),3 )
        end
    end
    this.stone_Active (false )
--------------------------------------------------------------------------------
end


This is the coding that is put in onEnterFrame
Code: Select all
function DemonBoard.onEnterFrame (  )
--------------------------------------------------------------------------------
   local gPattern=this.stone_Active ( )
    local isSleeping=this.isSleeping ( )
    log.message ( "In ONENTERFRAME FUNCTION" )
    --lets test to see if the scene if fully loaded
    log.error ( "Table Size=",table.getSize(this.Pattern ( )))
        --shape.overrideMeshSubsetMaterialOpacity ( this.getObject ( ),0,0,100 )
     if(this.player_Turn ( )==false)then
            if(gPattern==false and isSleeping==false)then
                --log.error ( "Let's play pattern" )
                this.GeneratePattern ( )
                this.stone_Active (true )
       
           end 
           --if(this.patternPlaying ( ))
                this.PlayPattern ( )
           --end
            --this.Wait (this.wait_Time ( ))
            --log.message ( "DeActivating Stone" )
            --this.DeActivateStone ( )
           
        else
            --This is where we get the player to press
            log.message ( "Player Turn" )
           
        end   
end


Play Pattern Function
Code: Select all
function DemonBoard.PlayPattern ( )
--------------------------------------------------------------------------------
   local tablesize=table.getSize ( this.Pattern ( ) )
    local playPattern=0
    local isSleeping=this.isSleeping ( )
   
   --lets access the table
    repeat
        if(table.getAt ( this.Pattern ( ),playPattern)=="red")then
           this.var_Color ("red")
        end
        if(table.getAt ( this.Pattern ( ),playPattern)=="blue")then
          this.var_Color ("blue" )
        end
        if(table.getAt ( this.Pattern ( ),playPattern)=="green" )then
            this.var_Color ("green")
        end
        if(table.getAt ( this.Pattern ( ),playPattern)=="brown" )then
           this.var_Color ("brown")
        end
        this.ActivateStone ( )
       
        this.Wait (this.wait_Time ( ))
        isSleeping=this.isSleeping ( )
        if(isSleeping==true)then
          log.message ( "Attempting to DeActivate" )
         this.DeActivateStone ( )
         this.isSleeping (false )
         log.message ( "DeActivated" )
        end
        playPattern=playPattern+1
    until playPattern==tablesize
--------------------------------------------------------------------------------
end

When I have the code access this DeActivateStone then the object doesn't go invisible. So I can see the result I have a wait function that waits like 8 secs before making it visible again. Or suppose to :/
RedQueen
Platinum Boarder
Platinum Boarder
 
Posts: 328

Re: Opacity Override Issue

Postby RedQueen » 18 May 2012, 01:14

I have tried.

object.setVisible(), shape.setMeshOpacity(), shape.overrideMeshMaterialEmissive() <-This to make the glow effect and yet the results is the same. And it just doesn't function the way it should. The only reason I am pretty sure the coding is right I created a prototype in another engine and the same coding and setup functions correctly so I don't understand what Shiva is doing that it will not work. I am pulling my hair out I would hate to have to scrap this :|. And I believe I have programmed more complex things then this.

Also I even separated the objects so that I wouldn't be referencing children. Nothing.
RedQueen
Platinum Boarder
Platinum Boarder
 
Posts: 328

Re: Opacity Override Issue

Postby gn0me » 18 May 2012, 03:12

hi
Are you sure that your nSubsetIndex is right ?
Thats only thing i can think of, eventually Factor - personally im trying to keep it at 1. :)
| Shiva 1.9.2b2 / Celeron G530 / HD 6770 | Android 4.04 |
User avatar
gn0me
Expert Boarder
Expert Boarder
 
Posts: 86
Location: pl

Re: Opacity Override Issue

Postby RedQueen » 18 May 2012, 04:10

Here is the weird thing the function activatestone which hides the objects works when i dont access the deactivate stone function which unhides it again.so simple it goes hide the stone wait three seconds and then unhide. Well that is what it is suppose to do but dont.
RedQueen
Platinum Boarder
Platinum Boarder
 
Posts: 328

Re: Opacity Override Issue

Postby neilb » 18 May 2012, 12:11

Does hiding the stone work at all? For instance, if you call overrideMeshSubsetMaterialOpacity and set the opacity to 1, then on the line following, set it to 0, will the stone vanish? If so, then that would make the problem more likely to be something in your code.

Another test would be to set the stone opacity to 0.5 instead of 0. If that works, but setting it to 0 doesn't then that would make it more likely to be something in Shiva.

I'd also try calling getMeshOpacity, getMeshSubsetMaterialOpacityOverride and getMeshSubsetMaterialOpacityThresholdOverride and log the values before and after the call to overrideMeshSubsetMaterialOpacity both where the counter is hidden and where it is made visible again, to make sure the values going in are what you expect them to be.

Last thing, I'd fix the third parameter which should be in the range 0 to 1. It shouldn't make a difference, but you might have discovered a Shiva bug.

I'm not sure what takes precedence - getMeshOpacity or overrideMeshSubsetMaterialOpacity? Perhaps you need to set the mesh opacity to 0 to allow the subset override to work? Logically, it shouldn't work that way, but you never know...
neilb
Platinum Boarder
Platinum Boarder
 
Posts: 463
Location: Adelaide, South Australia

Re: Opacity Override Issue

Postby RedQueen » 18 May 2012, 13:46

It works when I don’t access the DeActivate function which does what you mention it un-hides it. So if I don’t have the DeActivate function all works fine. And I have been through the DeActivate function numerous times and don’t see what would cause this fault.

It does the same thing the Activate function does just inversed.

The video I posted earlier shows the debugger running that even though it goes to the override command it doesn’t do what it is suppose to and make it invisible just because the DeActivate function is called afterwords. If I comment out the DeActivate function it does it.
The results is suppose to be a little something like this-
http://www.youtube.com/watch?v=U2Ex-G5H5rc

Being that it seems SIMON isn’t a universal game I guess majority of people have no clue how it works when I mentioned that was what I was trying to implement in a way.

**NOTE**

I did what you suggested and put one line after the other one hide and one unhide and still it doesn't do it.
Code: Select all
if(activeColor=="blue")then
    log.error ( this.getObject ( ) )
    shape.overrideMeshSubsetMaterialOpacity (this.getObject ( ),3,0,1)
    shape.overrideMeshSubsetMaterialOpacity (this.getObject ( ),3,1,1)

    --lets play sound
    sound.play ( this.getObject ( ),0,1,false,1 )
   end   


Its like you can't have multiple material manipulation commands at once.
RedQueen
Platinum Boarder
Platinum Boarder
 
Posts: 328

Re: Opacity Override Issue  [SOLVED]

Postby neilb » 18 May 2012, 15:24

I've had another look at your code and something doesn't look right.

Based on the code you've posted, it looks like you've got onEnterFrame calling PlayPattern which contains a loop that cycles through the list of moves. I don't think this will work because all the code to play the pattern appears to be run inside a single call of the onEnterFrame. Shiva only updates the state of objects in a scene at the start of the next frame, which would explain why you wouldn't see any change - ie. the app is running through the entire pattern of showing and hiding stones without the scene being updated.

If I'm right, then one solution would be to change onEnterFrame so that each time it's called, it checks some sort of timer to see if it should display the next move. If the timer has run out, then it updates the stones with the next move then resets the timer. This continues until there are no more moves and it's the player's turn.
neilb
Platinum Boarder
Platinum Boarder
 
Posts: 463
Location: Adelaide, South Australia

Re: Opacity Override Issue

Postby RedQueen » 18 May 2012, 18:05

Hmmm..I had that thought at the back of my head. I will try once I get home from work and report back.

Thx neilb! :D
RedQueen
Platinum Boarder
Platinum Boarder
 
Posts: 328

Re: Opacity Override Issue

Postby RedQueen » 18 May 2012, 21:22

That was it!! I re-structed it like you said and now it flashes as it should. Thank you so much Neilb I blow many kisses of appreciate!! :D. Goes to show you execution is very vital.
RedQueen
Platinum Boarder
Platinum Boarder
 
Posts: 328


Return to Game programming