Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

Adding script to already built script code


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 abrken   Members   -  Reputation: 130

Like
0Likes
Like

Posted 08 August 2004 - 10:58 PM

Hello, I don't know how to make this : 1/ I got some script that are built using engine->AddScriptSection() then engine->Build(..) . The script is made of different functions (engine->AddScriptSection). 2/ When I want one function to execute, I call engine->GetFunctionIDByName() then context->Prepare() and context->Execute(). The Problem : A function call can result in a new script. The resulting script can call function(s) that have been built in 1/ . What I have tried : Using the same module name, I call engine->AddScriptSection() then engine->build() result in only new ScriptSection added that could be used. The other functions that have been build in 1/ are deleted (Reset()). Using another module name, I'm doing the same and the result is the same. Question: How can I make it ? Does the module implementation that's been discussed in thread "Call into a Module" (module::function) is being developped ? Thank's for any suggestion. AbrKen

Sponsor:

#2 Gyrbo   Members   -  Reputation: 187

Like
0Likes
Like

Posted 08 August 2004 - 11:09 PM

I don't think that what you want is currently possible. You might be able to do it using ExecuteString().

What exactly do you need the script to generate another script? It might be possible to change you method to not use this.

#3 abrken   Members   -  Reputation: 130

Like
0Likes
Like

Posted 08 August 2004 - 11:29 PM

What I'm doing is a kind of browser where there is no Internet.

You navigate in an Xml defined tree. To Navigate you define some hot spots (or hot keys) that when clicked (or pushed) execute some scripts (that can result in navigation) or just navigate.

Those scripts could result in database access to generate new pages or just picture grabbing that have hot spot dynamically defined, and of course the resulting hot spot action can be just navigate or execute some script.

Those dinamicaly generated scripts can use global functions defined in the global Xml tree.

sample :

<XPNTree>
<TIMEOUT Elapse=30000/>
<COMMON>
<CODE Name="GLOBAL">
<!--
bool AddCharToCode(bstr &in_bStrChar) {
bool bRet = false;
CLuaXmlPresenter *xmlPresenter;
bstr bstrCodeActif;
int iTextActif;

Navigator.ResetTimeoutTimer();

xmlPresenter = getReferencedPresenter("XPNPresenter");
bstrCodeActif = GetReferencedVarCString("CODE ACTIF");
iTextActif = GetReferencedVarInt("TEXT ACTIF");

if (xmlPresenter != 0) {
CLuaXmlPresenterElementText *xmlText = xmlPresenter->GetText(iTextActif);
CLuaXmlPresenterElementText *xmlTextMsg = xmlPresenter->GetText(70);
if (xmlText != 0 && xmlTextMsg != 0) {
CString textString;
int iLen;

xmlTextMsg->SetText(textString);
textString = GetReferencedVarCString(bstrCodeActif);
iLen = textString.GetLength();
if (iLen < 4) {
CString csTextEchoed;
textString += in_bStrChar;
iLen++;
UpdReferencedVar(bstrCodeActif, textString);
while (iLen > 0) {
csTextEchoed += "*";
iLen--;
}
xmlText->SetText(csTextEchoed);
xmlText->Display(0, true);
bRet = true;
if (textString.GetLength() == 4) {
if (iTextActif == 50) {
csTextEchoed = "CODE2";
iTextActif = 60;
UpdReferencedVar("CODE ACTIF", csTextEchoed);
UpdReferencedVar("TEXT ACTIF", iTextActif);
csTextEchoed = "Saisissez à nouveau votre code.";
xmlTextMsg->SetText(csTextEchoed);
}
}
}
else {
MessageBeep(0);
}
xmlTextMsg->Display(0, true);
}
}
return bRet;
}

bool DelLastCharToCode() {
bool bRet = false;
CLuaXmlPresenter *xmlPresenter;
bstr bstrCodeActif;
int iTextActif;

Navigator.ResetTimeoutTimer();

PrintTrace("Retour Arrière");

xmlPresenter = getReferencedPresenter("XPNPresenter");
bstrCodeActif = GetReferencedVarCString("CODE ACTIF");
iTextActif = GetReferencedVarInt("TEXT ACTIF");

if (xmlPresenter != 0) {
CLuaXmlPresenterElementText *xmlText = xmlPresenter->GetText(iTextActif);
if (xmlText != 0) {
CString textString;
int iLen;
textString = GetReferencedVarCString(bstrCodeActif);
iLen = textString.GetLength();

if (iLen == 0 && iTextActif == 60) {
textString = "CODE1";
iTextActif = 50;
UpdReferencedVar("CODE ACTIF", textString);
UpdReferencedVar("TEXT ACTIF", iTextActif);
bstrCodeActif = textString;
textString = GetReferencedVarCString(bstrCodeActif);
iLen = textString.GetLength();
xmlText = xmlPresenter->GetText(iTextActif);
}

if (xmlText != 0 && iLen > 0) {
CString csTextEchoed;
iLen--;
textString.Delete(iLen, 1);
UpdReferencedVar(bstrCodeActif, textString);
while (iLen > 0) {
csTextEchoed += "*";
iLen--;
}
xmlText->SetText(csTextEchoed);
xmlText->Display(0, true);
bRet = true;
}
else {
MessageBeep(0);
}
}
}

return bRet;
}

bool ValidateCode() {
bool bRet = false;
CLuaXmlPresenter *xmlPresenter;
int iTextActif;

Navigator.ResetTimeoutTimer();
PrintTrace("Validation");

xmlPresenter = getReferencedPresenter("XPNPresenter");
iTextActif = GetReferencedVarInt("TEXT ACTIF");
if (xmlPresenter != 0) {
CLuaXmlPresenterElementText *xmlTextMsg = xmlPresenter->GetText(70);
if (xmlTextMsg != 0) {
CString csCode1, csCode2;
csCode1 = GetReferencedVarCString("CODE1");
csCode2 = GetReferencedVarCString("CODE2");
if (csCode1.GetLength() == 4 &&
csCode1 == csCode2) {
csCode1 = "CBAboTmpFra";
bRet = Navigator.AskForNavigate(csCode1);
}
else {
csCode1 = "Votre saisie est incorrecte! Saisir 4 chiffres.";
xmlTextMsg->SetText(csCode1);
xmlTextMsg->Display(0, true);
}
}
}
return bRet;
}
-->
</CODE>
<CODE Name="TheOtherCode">
<!--
bstr bstrTmp;
string strTmp;
CString csTmp;
CLuaXmlPresenter *xmlPresenter;

xmlPresenter = getReferencedPresenter("XPNPresenter");

if (xmlPresenter != 0) {
CXmlParameter xmlParam;
CXmlNode *pSubNode = 0;
bool bFound;

xmlParam.m_strName = "Id";
xmlParam.m_strValue = "10";

strTmp = "BITMAP";

bFound = xmlPresenter->findSubNode(strTmp, xmlParam, pSubNode);

if (bFound == true) {
strTmp = "DST_X";
bFound = pSubNode->getParameterValue(strTmp, xmlParam);
if (bFound == true) {
xmlParam.m_strValue = "10";
pSubNode->updXmlParameter(xmlParam);
}

strTmp = "DST_Y";
bFound = pSubNode->getParameterValue(strTmp, xmlParam);
if (bFound == true) {
xmlParam.m_strValue = "10";
pSubNode->updXmlParameter(xmlParam);
}

strTmp = "DST_CX";
bFound = pSubNode->getParameterValue(strTmp, xmlParam);
if (bFound == true) {
xmlParam.m_strValue = "100";
pSubNode->updXmlParameter(xmlParam);
}

strTmp = "DST_CY";
bFound = pSubNode->getParameterValue(strTmp, xmlParam);
if (bFound == true) {
xmlParam.m_strValue = "100";
pSubNode->updXmlParameter(xmlParam);
}
}
}
-->
</CODE>
<CODE Name="FlipImage">
<!--
bstr bstrTmp;
string strTmp;
CLuaXmlPresenter *xmlPresenter;

xmlPresenter = getReferencedPresenter("XPNPresenter");

if (xmlPresenter != 0) {
CLuaXmlPresenterElementBitmap *xmlBitmap;
xmlBitmap = xmlPresenter->GetBitmap(10);
if (xmlBitmap != 0) {
CImage *imageBitmap;
imageBitmap = xmlBitmap->GetImageBitmap();
if (imageBitmap != 0) {
imageBitmap->Flip();
xmlBitmap->Display(0, true);
}
}
}
-->
</CODE>
</COMMON>
<PAGE Name="AcceuilFra" File="Acceuil.xml" Default=1>
<TIMEOUT Elapse=0/>
<MOUSE>
<RECT Coord="0183,0012,0225,0041">
<NAV Name="AcceuilEng"/>
</RECT>
<RECT Coord="0289,0012,0328,0041">
<EXEC>
<!--FlipImage();-->
</EXEC>
</RECT>
<CIRC Coord="0024,0441,0074,0471">
<NAV Name="DispoFra"/>
</CIRC>
<CIRC Coord="0570,0441,0620,0471">
<NAV Name="EntreeFra"/>
</CIRC>
</MOUSE>
<OnBeforeParse>
<!--TheOtherCode();-->
</OnBeforeParse>
</PAGE>
<PAGE Name="AcceuilEng" File="Acceuil.xml">
<MOUSE>
<RECT Coord="0183,0012,0225,0042">
<NAV Name="AcceuilFra"/>
</RECT>
<POLY Coord="0235,0060,0260,0060,0228,0081,0228,0097,0244,0097,0222,0113,0205,0099,0220,0097,0220,0075,0235,0061">
<EXEC>
<!--FlipImage();-->
</EXEC>
</POLY>
</MOUSE>
<OnBeforeParse>
<!--TheOtherCode();-->
</OnBeforeParse>
</PAGE>
<PAGE Name="DispoFra" File="Disponibilite.xml">
<MOUSE>
<CIRC Coord="0024,0441,0074,0471">
<NAV Name="AcceuilFra"/>
</CIRC>
</MOUSE>
</PAGE>
<PAGE Name="EntreeFra" File="MenuPrincipal.xml">
<MOUSE>
<CIRC Coord="0024,0441,0074,0471">
<NAV Name="AcceuilFra"/>
</CIRC>
<CIRC Coord="0435,0131,0485,0161">
<NAV Name="AbonneFra"/>
</CIRC>
<CIRC Coord="0437,0199,0487,0229">
<NAV Name="AboTmpFra"/>
</CIRC>
<CIRC Coord="0437,0262,0487,0292">
<NAV Name="AcceuilFra"/>
</CIRC>
<CIRC Coord="0437,0325,0487,0355">
<NAV Name="AcceuilFra"/>
</CIRC>
</MOUSE>
</PAGE>
<PAGE Name="AbonneFra" File="AccesAbonne.xml">
<MOUSE>
<CIRC Coord="0024,0441,0074,0471">
<NAV Name="EntreeFra"/>
</CIRC>
<CIRC Coord="0570,0441,0620,0471">
<NAV Name="AcceuilFra"/>
</CIRC>
</MOUSE>
</PAGE>
<PAGE Name="AboTmpFra" File="AccesAboTmp.xml">
<MOUSE>
<CIRC Coord="0024,0441,0074,0471">
<NAV Name="EntreeFra"/>
</CIRC>
<CIRC Coord="0570,0441,0620,0471">
<NAV Name="SaisieCodeAboTmpFra"/>
</CIRC>
</MOUSE>
</PAGE>
<PAGE Name="SaisieCodeAboTmpFra" File="SaisieCodeAboTmp.xml">
<TIMEOUT Elapse=5000>
<NAV Name="EntreeFra"/>
</TIMEOUT>
<OnBeforeStart>
<!--
CString textString;
int iTextZone;
ReferenceVar("CODE1", textString);
ReferenceVar("CODE2", textString);
ReferenceVar("CODE ACTIF", textString);
ReferenceVar("TEXT ACTIF", iTextZone);
textString.Empty();
UpdReferencedVar("CODE1", textString);
UpdReferencedVar("CODE2", textString);
textString = "CODE1";
UpdReferencedVar("CODE ACTIF", textString);
iTextZone = 50;
UpdReferencedVar("TEXT ACTIF", iTextZone);
-->
</OnBeforeStart>

<MOUSE>
<CIRC Coord="0024,0441,0074,0471">
<NAV Name="EntreeFra"/>
</CIRC>
<CIRC Coord="0344,0117,0400,0148">
<EXEC>
<!--
AddCharToCode("1");
-->
</EXEC>
</CIRC>
<CIRC Coord="0424,0117,0480,0148">
<EXEC>
<!--
AddCharToCode("2");
-->
</EXEC>
</CIRC>
<CIRC Coord="0502,0117,0558,0148">
<EXEC>
<!--
AddCharToCode("3");
-->
</EXEC>
</CIRC>
<CIRC Coord="0346,0318,0402,0374">
<EXEC>
<!--
DelLastCharToCode();
-->
</EXEC>
</CIRC>
<CIRC Coord="0504,0318,0560,0374">
<EXEC>
<!--
ValidateCode();
-->
</EXEC>
</CIRC>
</MOUSE>
<KEYBOARD>
<KEY Name="VK_0"><EXEC><!--if (Navigator.m_bKeyDown) AddCharToCode("0");--></EXEC></KEY>
<KEY Name="VK_1"><EXEC><!--if (Navigator.m_bKeyDown) AddCharToCode("1");--></EXEC></KEY>
<KEY Name="VK_2"><EXEC><!--if (Navigator.m_bKeyDown) AddCharToCode("2");--></EXEC></KEY>
<KEY Name="VK_3"><EXEC><!--if (Navigator.m_bKeyDown) AddCharToCode("3");--></EXEC></KEY>
<KEY Name="VK_4"><EXEC><!--if (Navigator.m_bKeyDown) AddCharToCode("4");--></EXEC></KEY>
<KEY Name="VK_5"><EXEC><!--if (Navigator.m_bKeyDown) AddCharToCode("5");--></EXEC></KEY>
<KEY Name="VK_6"><EXEC><!--if (Navigator.m_bKeyDown) AddCharToCode("6");--></EXEC></KEY>
<KEY Name="VK_7"><EXEC><!--if (Navigator.m_bKeyDown) AddCharToCode("7");--></EXEC></KEY>
<KEY Name="VK_8"><EXEC><!--if (Navigator.m_bKeyDown) AddCharToCode("8");--></EXEC></KEY>
<KEY Name="VK_9"><EXEC><!--if (Navigator.m_bKeyDown) AddCharToCode("9");--></EXEC></KEY>
<KEY Name="VK_NUMPAD0"><EXEC><!--if (Navigator.m_bKeyDown) AddCharToCode("0");--></EXEC></KEY>
<KEY Name="VK_NUMPAD1"><EXEC><!--if (Navigator.m_bKeyDown) AddCharToCode("1");--></EXEC></KEY>
<KEY Name="VK_NUMPAD2"><EXEC><!--if (Navigator.m_bKeyDown) AddCharToCode("2");--></EXEC></KEY>
<KEY Name="VK_NUMPAD3"><EXEC><!--if (Navigator.m_bKeyDown) AddCharToCode("3");--></EXEC></KEY>
<KEY Name="VK_NUMPAD4"><EXEC><!--if (Navigator.m_bKeyDown) AddCharToCode("4");--></EXEC></KEY>
<KEY Name="VK_NUMPAD5"><EXEC><!--if (Navigator.m_bKeyDown) AddCharToCode("5");--></EXEC></KEY>
<KEY Name="VK_NUMPAD6"><EXEC><!--if (Navigator.m_bKeyDown) AddCharToCode("6");--></EXEC></KEY>
<KEY Name="VK_NUMPAD7"><EXEC><!--if (Navigator.m_bKeyDown) AddCharToCode("7");--></EXEC></KEY>
<KEY Name="VK_NUMPAD8"><EXEC><!--if (Navigator.m_bKeyDown) AddCharToCode("8");--></EXEC></KEY>
<KEY Name="VK_NUMPAD9"><EXEC><!--if (Navigator.m_bKeyDown) AddCharToCode("9");--></EXEC></KEY>
<KEY Name="VK_RETURN"><EXEC><!--if (Navigator.m_bKeyDown) ValidateCode();--></EXEC></KEY>
<KEY Name="VK_BACK"><EXEC><!--if (Navigator.m_bKeyDown) DelLastCharToCode();--></EXEC></KEY>
</KEYBOARD>
</PAGE>
<PAGE Name="CBAboTmpFra" File="CBAboTmpFra.xml">
<TIMEOUT Elapse=30000>
<NAV Name="EntreeFra"/>
</TIMEOUT>
<MOUSE>
<CIRC Coord="0024,0441,0074,0471">
<NAV Name="EntreeFra"/>
</CIRC>
</MOUSE>
</PAGE>
</XPNTree>



In this sample you can see in XPNTree.COMMON a tag named CODE with name="GLOBAL". There you can find some AngelScript Global Functions that are used somewhere else (see near the end of the xml the AddCharToCode function call).



#4 Andreas Jonsson   Moderators   -  Reputation: 3227

Like
0Likes
Like

Posted 09 August 2004 - 02:08 AM

It is not yet possible to make calls between modules. This is coming in a near future. Can't say exactly when, but hopefully with version 1.9.0.

The current recommendation is to concatenate the scripts and rebuild them all. That is, call AddScriptSection() with the global scripts again, then AddScriptSection() with the new scripts, then Build(). You'll need to do this each time any part of the script changes.


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#5 abrken   Members   -  Reputation: 130

Like
0Likes
Like

Posted 09 August 2004 - 02:20 AM

Thank's for the replies.

Quote:
This is coming in a near future.


I'm going to wait for 1.9.x, until then Global script functions wont be callable by added script.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS