question

Kevin A2 avatar image
0 Likes"
Kevin A2 asked Phil BoBo edited

When adding codes to the XboxInput node, it is not working

I tried closing the 3D model view and open again after writing the codes, but the code still not comes to effect.

Also when I saved and closed the file, I open the file again and the codes I wrote are gone. Why? Thanks

FlexSim 17.2.5
xbox controller
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Steven Hamoen avatar image
0 Likes"
Steven Hamoen answered Phil BoBo edited

@Kevin A2 Where did you write the codes? Can you give a screenshot of the tree with the top node? This is very little information to go on but what I guess is that you have written it on the active window? A window that you see is always an instance of the class. So if you open and close the windows or close and open Flexsim, you destroy the instance and your code is gone. I think you should look into creating a module and use that to change the class of the view and write your code there.

For testing it should work if you put it on the instance but have you build the node as Flexscript?

· 9
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Kevin A2 avatar image Kevin A2 commented ·

@steven.hamoen

Hi Steven,

I wrote the code on the node "VIEW:/standardviews/documentwindows/Perspective>eventfunctions/XboxInput"

I want to assign an action to the X button of the xbox controller and wrote this:

if (wButtons & XINPUT_GAMEPAD_X)
            openoutput(theBufferInBewteen);

(where "theBufferInBetween" is a global variable)

Yet when I run the model, I press the X button on the controller and it is not working; while it works when I put the code in a button on dashboard.

Thanks!

0 Likes 0 ·
screenshot-1.png (159.0 KiB)
screenshot-2.png (173.2 KiB)
Steven Hamoen avatar image Steven Hamoen Kevin A2 commented ·

@Kevin A2

Ok this at least answers your question about why your code is missing when you close and open the file. You are putting the code in the right place only thing is that if you save in Flexsim you only save the model. The tree cannot be touched by the user unless you use a module. So once you have your solution working go read up about creating a module to adapt Flexsim. This post tells you where can download the SDK Post with SDK link

For your questions why it is not working you have to simply apply the art of debugging:

1. If you close and reopen the window and you go to: right click->view-> explore structure is your code still there?

2. if your code is still there, is the code called (I'm not sure if you can use the debugger directly but create a message box (msg()) is also a good option

3. if that works you have to check if your conditions are both valid etc.

then you should find out why it not doing what you think it should do..

0 Likes 0 ·
Kevin A2 avatar image Kevin A2 Steven Hamoen commented ·

@steven.hamoen

Hi Steven,

I figured out that I didn't press "Build FlexScript" & "Compile Model" after adding my code; when I press these buttons, and close & re-open 3D view, the code works.

By the way, I found that the Xbox controller is too responsive. When I press (not holding) the X button of the controller just once, FlexSim sees it as I am pressing the button 3 to 4 times. Is there any way to solve this? Thanks.

1 Like 1 ·
Show more comments
Steven Hamoen avatar image Steven Hamoen commented ·

@Kevin A2 Hi Kevin, compile model should not be necessary if you don't use C++. Build Flexscript should be enough. Considering the too responsiveness, here I have no idea. Maybe @phil.bobo can say something logical about it?

0 Likes 0 ·
Kevin A2 avatar image Kevin A2 commented ·

@steven.hamoen @phil.bobo Thank you very much!

0 Likes 0 ·
Phil BoBo avatar image Phil BoBo ♦♦ Kevin A2 commented ·

Note that any changes you make to the VIEW tree will be gone when you close and reopen FlexSim. To change the VIEW tree, you should use the Module SDK.

0 Likes 0 ·
Kevin A2 avatar image Kevin A2 Phil BoBo ♦♦ commented ·

@phil.bobo

I've tried working on this but I have no idea how to do it

"For example, if you want to execute code just once when it is initially pressed, store a variable on the view to tell when the code has fired but the button hasn't been released yet. Then only execute the code if that variable is false and the button is pressed. In the code, set that variable to true. If the button is not pressed, set that variable back to false."

Could you give an example on it?

Also, it seems that "stick(controller, STICK_XBOX_BUTTONS)" command returns different values when different buttons of controller is pressed (e.g. 4096, 8192, 16384), what does they mean? Thanks.

0 Likes 0 ·
Show more comments