First, there is a workaround. So you can continue (Andreas) working on native arrays.
This is what's going on.
I've got a C++ class that expose variables to script :
in_pAsEngine->RegisterObjectType("CXPNTree", sizeof(CXmlValue), asOBJ_CLASS);
in_pAsEngine->RegisterObjectProperty("CXPNTree", "uint16 m_wMsgParam", offsetof(CXPNTree, m_wMsgParam));
in_pAsEngine->RegisterObjectProperty("CXPNTree", "uint32 m_lMsgParam", offsetof(CXPNTree, m_lMsgParam));
As you can see, there is no 'const' keyword.
Then in a script I was doing this :
// --------------------------------------
// XPNTree : Message SKFPresenceDetection
// --------------------------------------
CString csPageNameWait("Wait");
switch ( Navigator.m_wMsgParam) {
case 3 :
Navigator.AskForNavigate(Navigator.m_csDefaultPageName);
break;
case 4 :
Navigator.AskForNavigate(csPageNameWait);
break;
}
This script code wasn't working.
So I have put some trace using a MessageBox.
// --------------------------------------
// XPNTree : Message SKFPresenceDetection
// --------------------------------------
CString csPageNameWait("Wait");
bstr bstrTmp = bstrFormat(Navigator.m_wMsgParam);
MessageBox(Presenter.GetHwndPresenter(), bstrTmp, "Detection", 0);
switch ( Navigator.m_wMsgParam) {
case 3 :
MessageBox(Presenter.GetHwndPresenter(), "Présence", "Detection", 0);
Navigator.AskForNavigate(Navigator.m_csDefaultPageName);
break;
case 4 :
MessageBox(Presenter.GetHwndPresenter(), "Absence", "Detection", 0);
Navigator.AskForNavigate(csPageNameWait);
break;
}
The MessageBox was telling me that Navigator.m_wMsgParam get value of 3 and 4 but, the switch case wasn't working (no messagebox displayed).
So I decided to take another way.
Declare an int in the script then assign it the value then do the switch case on that int. That was a mistake (m_wMsgParam is declared as uint16).
int iSwitch = Navigator.m_wMsgParam;
CString csPageNameWait("Wait");
bstr bstrTmp = bstrFormat(Navigator.m_wMsgParam);
MessageBox(Presenter.GetHwndPresenter(), bstrTmp, "Detection", 0);
switch (iSwitch) {
case 3 :
MessageBox(Presenter.GetHwndPresenter(), "Présence", "Detection", 0);
Navigator.AskForNavigate(Navigator.m_csDefaultPageName);
break;
case 4 :
MessageBox(Presenter.GetHwndPresenter(), "Absence", "Detection", 0);
Navigator.AskForNavigate(csPageNameWait);
break;
}
AS gives me "Can't implicitly convert from 'const uint' to 'int'"
I get arounf this error doing a cast :
int iSwitch = int(Navigator.m_wMsgParam);
And magically, the script was working fine.
Conclusion :
The external variable was found to be 'const' without the explicit specification from me. This const leads to the switch not to be evaluated (I think).
What do you think about that ?
AbrKen.