Joystick in TS7.5

About Truespace Archives

These pages are a copy of the official truespace forums prior to their removal somewhere around 2011.

They are retained here for archive purposes only.

Joystick in TS7.5 // Scriptorium

1  |  

Post by Wigand // May 12, 2007, 2:29am

Wigand
Total Posts: 462
pic
Emma already told me, that my joystick script will not work in TS7.5.

Did caligari change something in the scripting?

Post by TomG // May 14, 2007, 1:20am

TomG
Total Posts: 3397
Hi!


Yes the scripting underwent a lot of improvements and changes. As a result some scripts will need updating - the good side of that is you can accomplish much more in scripting thanks to the fixes and improvements in there.


Do feel free to expore example scripts and documentation for changes, and to post what is no longer working, there are many fine beta testers who have explored the scripting and will be happy to help find out where things have changed that might affect your script. Norm too of course at Caligari is something of a scripint genius and is very familiar with the scripting changes.



For simplicity, I would repost the script as an attachment, so everyone knows exactly what script and version to be checking.


HTH!

Tom

Post by Wigand // May 14, 2007, 6:51am

Wigand
Total Posts: 462
pic
Hi!


Yes the scripting underwent a lot of improvements and changes. As a result some scripts will need updating - the good side of that is you can accomplish much more in scripting thanks to the fixes and improvements in there.


Tom


Some more hints to find the hidden easter eggs would be great. :rolleyes:

In other words: Where are the documentations of the changes in scripting?

We scripters are still waiting for exact and complete docus for every object

and parameter.

:(

Post by ProfessorKhaos // May 14, 2007, 3:17pm

ProfessorKhaos
Total Posts: 622
pic
Correct me if I'm wrong but doesn't the joystick script make use of a 3rd party .dll ? The reason I ask is because I'm not entirely sure how compatible the .dll itself is with other applications in general and whomever helps you will need to know what you're using with your script.


If I recall, most of the script changes had to do with creating separate memory spaces for each script such that they wouldn't interfere with one another's variables and the establishment of a new VBScript brick that could contain common functions.


I do agree that per-method documentation would be a huge plus. I've already seen some significant steps in that direction by the users themselves. Personally, I find examples to be of more value than mere reference guides alone though and I think that's what you'll see more and more of. I hope we see both! :)

Post by Wigand // May 16, 2007, 7:14am

Wigand
Total Posts: 462
pic
This is the dll code:

You can see it uses DirectX7.

I found it in the internet and made some small changes.

One thing I am not sure is the "WindowFromPoint" function.

I use it to get a window handle. Maybe it is not more possible to do it

this way. If TS could give its windowhandle it would be easier to make some

interaction with dlls and other programs.


If someone has an idea, please let me know.


(Sorry, the comments are in german)





Dim DX As New DirectX7

Dim DI As DirectInput

Dim diJoystick() As DirectInputDevice

Const JOYSTICKCENTERED = 32768

Dim JSButton() As Single

Dim Button() As Long

Dim JSDevices As Collection

Public Count

Public Devicename As String


Private Declare Function GetCursorPos Lib "user32" _

(lpPoint As POINTAPI) As Long


Private Declare Function WindowFromPoint Lib "user32" (ByVal _

xPoint As Long, ByVal IyPoint As Long) As Long


Private Type POINTAPI

x As Long

y As Long

End Type


Dim poiMaus As POINTAPI





Public Function DInput_Init(WHandle) As Boolean

Dim Caps As DIDEVCAPS

Dim diEnumObjects As DirectInputEnumDeviceObjects

Dim enumDevice As DirectInputEnumDevices

Dim i As Single


On Error GoTo ErrEnd



'erstelle das DirectInput-Objekt

Set DI = DX.DirectInputCreate()

Set JSDevices = New Collection



'Auflistung aller angeschlossenen Joysticks einlesen

Set enumDevice = DI.GetDIEnumDevices(DIDEVTYPE_JOYSTICK, DIEDFL_ATTACHEDONLY)



Count = enumDevice.GetCount

If enumDevice.GetCount = 0 Then

MsgBox "There are no joysticks.", vbInformation

Exit Function

End If




ReDim diJoystick(enumDevice.GetCount) As DirectInputDevice

ReDim JSButton(enumDevice.GetCount) As Single

'und nun pro Joystick

For i = 1 To enumDevice.GetCount

'setze Input-Objekt pro Joystick

Set diJoystick(i) = DI.CreateDevice(enumDevice.GetItem(i).GetGuidInsta nce)

'hole Produktname



JSDevices.Add enumDevice.GetItem(i).GetProductName

Devicename = enumDevice.GetItem(i).GetProductName & " " & i

'setze DirectInput DatenFormat auf Joystick

diJoystick(i).SetCommonDataFormat DIFORMAT_JOYSTICK

'setze cooperative Level ???



GetCursorPos poiMaus

WHandle = WindowFromPoint(poiMaus.x, poiMaus.y)






diJoystick(i).SetCooperativeLevel WHandle, DISCL_BACKGROUND Or DISCL_EXCLUSIVE

'hole Fähigkeiten des Joysticks

diJoystick(i).GetCapabilities Caps

'irgendwelche Fähigkeiten hat der Joystick hoffentlich

If Caps.lFlags Then

'hole Button-Auflistung vom Joystick

Set diEnumObjects = diJoystick(i).GetDeviceObjectsEnum(DIDFT_BUTTON)

'wieviele Button hat der Joystick

JSButton(i) = diEnumObjects.GetCount

ReDim Button(i, diEnumObjects.GetCount)

diJoystick(i).Acquire

diJoystick(i).Poll

Set diEnumObjects = Nothing

End If

Next i



DInput_Init = True

Exit Function

ErrEnd:

' MsgBox "Direct Input could not be initialised!" & vbCr & _

' "", vbExclamation

' DInput_Init = False

End Function




Public Function JSX(Devicenumber)

Dim JoystickState As DIJOYSTATE



On Error Resume Next

'stelle Verbindung her

diJoystick(Devicenumber).Acquire

'mache Daten verfügbar

diJoystick(Devicenumber).Poll

'hole aktuelle Daten

diJoystick(Devicenumber).GetDeviceState Len(JoystickState), JoystickState

JSX = (JoystickState.x - JOYSTICKCENTERED)



End Function


Public Function JSY(Devicenumber)

Dim JoystickState As DIJOYSTATE



On Error Resume Next

'stelle Verbindung her

diJoystick(Devicenumber).Acquire

'mache Daten verfügbar

diJoystick(Devicenumber).Poll

'hole aktuelle Daten

diJoystick(Devicenumber).GetDeviceState Len(JoystickState), JoystickState

JSY = (JoystickState.y - JOYSTICKCENTERED)



End Function


Public Function JSZ(Devicenumber)

Dim JoystickState As DIJOYSTATE


On Error Resume Next

'stelle Verbindung her

diJoystick(Devicenumber).Acquire

'mache Daten verfügbar

diJoystick(Devicenumber).Poll

'hole aktuelle Daten

diJoystick(Devicenumber).GetDeviceState Len(JoystickState), JoystickState

JSZ = (JoystickState.z - JOYSTICKCENTERED)



End Function


Public Function copyright()


copyright = "This ActiveXDll is adapted from VBFun by M.Ehrhardt in 20070129. No warranty, use by your own risk"


End Function



Public Function CheckButton(Devicenumber, Buttonnumber)

Dim JoystickState As DIJOYSTATE


On Error Resume Next

'stelle Verbindung her

diJoystick(Devicenumber).Acquire

'mache Daten verfügbar

diJoystick(Devicenumber).Poll

'hole aktuelle Daten

diJoystick(Devicenumber).GetDeviceState Len(JoystickState), JoystickState




If JoystickState.buttons(Buttonnumber) > 0 Then

CheckButton = True

Else

CheckButton = False

End If



End Function


Public Function JSPOV(Devicenumber)

Dim JoystickState As DIJOYSTATE



On Error Resume Next

'stelle Verbindung her

diJoystick(Devicenumber).Acquire

'mache Daten verfügbar

diJoystick(Devicenumber).Poll

'hole aktuelle Daten

diJoystick(Devicenumber).GetDeviceState Len(JoystickState), JoystickState

JSPOV = (JoystickState.POV(0)) ' - JOYSTICKCENTERED)



End Function
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2024. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn