Assigning a coroutine to a Mind


#1

I didn’t want to reply to the old Mind forum post because I’m assuming it’s outdated by now. After all, it had this:

but:
//---------------------------------------------------------------------------------------
// Master instance constructor
//---------------------------------------------------------------------------------------

() 
  [
  Debug.println("Member: Master.!() - Mind instance constructor called.")
  ]

Anyway,

I’m afraid I do not quite understand this. If I have a class (using the tutorials, let’s use BP_Cube) and something happens and I wish to trigger a _pulsate coroutine from BP_Cube.

so in BP_Cube:
(added a PointLight in BP)

Real @pulsate_time

something_happened
&blueprint
() 
  [
    @pulsate_time : 0.0
    // How do I have this run in the Level2 mind instead of the Master mind?
    branch [ _pulsate ] 
  ]

_pulsate
() 
  [
  	// How can I tell what Mind is controlling this coroutine?
    @pulsate_time : @pulsate_time + GameLib.world_delta_seconds
    @point_light.intensity_set(MathLib.abs(5000.0 * MathLib.sin(@pulsate_time)))
  ]

The way that I’ve found is to add a function to the Level2 mind and have the BP_Cube call that. So:

BP_Cube::something_happened
&blueprint
() 
  [
  if Level2.instance? 
    [ 
    Level2.instance.something_happened(self)
    ]
 else 
    [ 
    @pulsate_time : 0
    branch [ _pulsate ]
    ]    
   ]

// and in Level2::something_happened
(BP_Cube cube) 
  [
  cube.@pulsate_time : 0.0
  branch [  cube._pulsate ]
  ]

However, it feels I’m missing some easier syntax that wouldn’t require changing the mind script every time that I wanted to have a coroutine being managed by it.

Also, is there any way to query, inside a coroutine, which mind is running it at the moment?

Thanks.


#2

Hello @silvio,

Thanks for all the digging you are doing!

We have a good mechanism for this.

We’ve just been caught up in GDC booth preparations so I hope to give you a detailed answer once I’m freed up a bit…


#3

Apologies for the much delayed response - GDC (which was great!) and its aftermath ate up a lot of our time.

First of all, please get latest from P4 (2017-03-10 afternoon. Version 3.0.4304 and up) as we have added a number of improvements in the meantime.

We have also updated the above article on Mind objects to clarify things, and updated the article about the change command as well.

Any method or couroutine called on a mind object (as a receiver/this) automatically uses that mind as an updater.
Any coroutine called on a non-mind object travels up the stack to inherit any updater mind that is being used by its callers or it defaults to the master mind if there is no obvious mind to inherit.

To change the mind that updates one or more expressions (such as with your something_happened example) you use the change command.

To query which mind is currently used to update a routine, you use the this_mind identifier.
So you can call println("Current mind: " this_mind) as an easy way to print out the current mind.

This is one of the more core aspects of SkookumScript, though it is also an area that most scripters don’t need to expend mental energy on a regular basis. For the most part, you have specific minds that update particular missions, ambient world, etc. and then the coroutines that are created within those minds automatically inherit the same minds for updating and logical grouping.

If you would like any more info or clarity in this area, just let us know. :madsci:


Great curated posts to learn about SkookumScript