Help with Pluginstate and Odakyufan Plugin

View previous topic View next topic Go down

Help with Pluginstate and Odakyufan Plugin

Post by waterburn on Fri Nov 07, 2014 2:55 am

Hi all,

I have been attempting to use the pluginstate[i]  variable inside the .animated file to scroll the rollsign without success. I have tried adding a line in the C# file of the Odakyufan plugin where the appropriate key is pressed down ie.

case VirtualKeys.K:   
this.Train.Panel[14]=1;           

This just does not seem to be working:

TextureShiftYDirection = 0, 1
TextureShiftYFunction = value + (0.0020 * pluginstate[14])

Any ideas?

waterburn

Posts : 54
Join date : 2012-06-29

Back to top Go down

Re: Help with Pluginstate and Odakyufan Plugin

Post by leezer3 on Fri Nov 07, 2014 1:21 pm

Not sure that's likely to work at all in it's current state.

Try this for the function (Off the top of my head):
TextureShiftYFunction = value + delta * (If[pluginstate[14] > 0 ,1,0] * 0.0020)

You may need to fiddle with the 0.0020 value to get the speed you want.

The plugin function is also unlikely to work in it's current state-
The default value for a pluginstate variable is zero. This is fine for your purposes Smile
However, the code snippet you've posted isn't any good. When the plugin hits the keypress down event, it'll change this value.
When you release the key, it'll still stay at one, and not drop back to zero. You need to add a line on the keypress up event to toggle it back to zero.

Cheers

Chris Lees

http://www.bvecornwall.co.uk

leezer3

Posts : 747
Join date : 2011-08-23

http://www.bvecornwall.co.uk

Back to top Go down

Re: Help with Pluginstate and Odakyufan Plugin

Post by waterburn on Sun Nov 09, 2014 2:34 am

Hi Chris,

Thanks so much for your reply. I have tried your suggestion. The rollsign just does not seem to move.. I have taken the train out of emergency to initialize the plugin. Also no plugin error messages in the F10 view.

waterburn

Posts : 54
Join date : 2012-06-29

Back to top Go down

Re: Help with Pluginstate and Odakyufan Plugin

Post by LabRatAndy on Sun Nov 09, 2014 2:15 pm

Waterburn's original formula looks like it should work, although assuming he wants the default down shift then TextureshiftYdirection line would not really be needed. 

I would say the formula would look something like this

TextureShiftYFunction = value + (pluginstate[14] * factor to shift by)

The if statment would not be needed as long as the value of pluginstate[14] can only be 1 or 0. I don't believe the delta statement would be needed as this is the time lapsed since the last call of the function and could mean the texture would shift regardless of the value of pluginstate[14]. You could aslo check the formula is correct by temporally changing pluginstate[14] to 1, which would cause it to texture shift all the time.
As for why the plugin code doesn't work having never looked at Odakyufan's code I cant give any sugestions.

LabRatAndy

Posts : 95
Join date : 2011-08-29

Back to top Go down

Re: Help with Pluginstate and Odakyufan Plugin

Post by waterburn on Mon Nov 10, 2014 1:58 am

I checked that this.Train.Panel[14] is correctly being set to 1 when I press the key by showing a message box. Do you think maybe pluginstate[14] in the .animated file is not the same as this.Train.Panel[14] in the plugin?

waterburn

Posts : 54
Join date : 2012-06-29

Back to top Go down

Re: Help with Pluginstate and Odakyufan Plugin

Post by LabRatAndy on Mon Nov 10, 2014 9:09 pm

They should be the same, but not having looked at Odakyufan's plugin I haven't got any suggestions as to why the value is not being set and passed back correctly.

LabRatAndy

Posts : 95
Join date : 2011-08-29

Back to top Go down

Re: Help with Pluginstate and Odakyufan Plugin

Post by leezer3 on Tue Nov 11, 2014 12:22 am

I think it's probably more likely either you or the plugin is resetting variable 14 somewhere in the code Smile


Let's go back to basics therefore.
At the start of the main elapse function (Train.cs) add this:
Code:
data.DebugMessage = Convert.ToString(Train.Panel[14]) + "- This is the current value";

This should update the debug message with the current value of variable 14 every frame.
Adding the little text message at the end shows us that we're seeing the correct variable, as opposed to something else being written there.
Now, when you press F10 to show the debug data, the current value of variable 14 should always be there.

Further points-
You shouldn't need to take the train out of emergency to initialise the plugin, this is a red herring.
The reason I tend to use the if statement is to avoid falling over unexpected values; I suppose it's unnecessary, but that's by the by.
Delta- Yes, I was thinking of wheels...

Post your source and I'll take a look Smile
Alternatively, one of the things on my list to add to BVEC_ATS is a variable which can be toggled through an arbitrary number of positions.
This would require a statefunction, rather than translate, but I can cook the function up easily.

Cheers

Chris Lees

http://www.bvecornwall.co.uk

leezer3

Posts : 747
Join date : 2011-08-23

http://www.bvecornwall.co.uk

Back to top Go down

Re: Help with Pluginstate and Odakyufan Plugin

Post by waterburn on Thu Nov 13, 2014 4:19 pm

Chris,

It seems you are right it is being reset under Train.cs in the elapse function:

// --- panel ---
                for (int i = 0; i < this.Panel.Length; i++) {
                    this.Panel[i] = 0;
                }

waterburn

Posts : 54
Join date : 2012-06-29

Back to top Go down

Re: Help with Pluginstate and Odakyufan Plugin

Post by leezer3 on Thu Nov 13, 2014 11:28 pm

That's not quite true- It's initializing it there but it's at the root of your problem.

It works like this (I don't explain it very well, but still):
The plugin provides an integer array (Length of 256 by default) to OpenBVE of plugin data.
This is reset each call, as the plugin isn't aware of any external states, just the data provided to it by OpenBVE when it's called.
Functions are also provided, which are called when jumping between stations.
The expected design philosophy is to continuously refresh the panel variable each call, by either adding it into the main elapse function or creating a separate device which updates it via it's own elapse function.


Try this instead:
On your keydown event, toggle a bool. This is *internal* to the plugin, as opposed to data being provided by the sim, and thus should be immutable in terms of sim data.
Use the keyup event to toggle the bool the other way.
Now, set a simple if-else in your elapse function to set panel variable 14 to either 0 or 1 depending on the state of this bool.

Problem solved Smile


[I think you could probably move the offending code to the initialise function as well, but that *may* play havoc with things I haven't thought of]

Cheers

Chris Lees

http://www.bvecornwall.co.uk

leezer3

Posts : 747
Join date : 2011-08-23

http://www.bvecornwall.co.uk

Back to top Go down

Re: Help with Pluginstate and Odakyufan Plugin

Post by waterburn on Sun Nov 16, 2014 1:31 am

It worked! Thanks Chris.

waterburn

Posts : 54
Join date : 2012-06-29

Back to top Go down

Re: Help with Pluginstate and Odakyufan Plugin

Post by Sponsored content Today at 2:31 pm


Sponsored content


Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum