Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 23rd, 2024, 3:43 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: code in external file
PostPosted: January 18th, 2009, 6:11 pm 
Offline

Joined: May 24th, 2007, 11:02 am
Posts: 132
Location: UK - Wales - Ceredigion
Opus: illuminatus > Evolution
OS: Windows 10 Pro
System: i7 8GB RAM
Is it possible to put a script in an external file (not compiled) - so that it can be edited with notepad?

(I need to put a script in a file that returns 1 or 0 based on what I pass it via opus.)

I want to give a client an .exe file with, for example, an .txt file that he can edit.

If he knew C etc, he could create a .dll file but that's not going to happen.

Any ideas?


Top
 Profile Visit website  
 
 Post subject:
PostPosted: January 18th, 2009, 10:42 pm 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
Jez,

I maybe don't understand all of the question. Here are some ideas to start.

1. OpusPro, at least v5.5 and later, already includes a provision in Script Object window/editing to "Set External File". This is a convenient way for you the developer to Save the script in an External File (.txt and possible other types in addition to Jez_script1.ils). I think if it is .ILS, and you leave it set as 'External'... Opus will run off of that when published. Someone correct me here.

That's all fine until published. Don't think client could access that directly after published.

2. Maybe... you give the client a copy as 'EditScript.txt' file, and then in Opus set an Action or a Script to read that file. Then write the contents to another External File, say 00000012.ils, in the SYS_PUBLICATION_DIR. This is 'tricky'. It might not work at all. Even if it could work, you will have to Publish pub once and determine what corresponding '000000xx.ils' filename Opus generates for that dev-time Jez_script1 file.

Depending on 'how much' editing you're giving to the client, you could read parameters in from a .INI file the client changes. Also, if that is not just parameters, you might bring parts of it in and use eval() commands.

This is an interesting Topic. Glad you brought it up.

[Lar Edit: You might look into Notepad++ for your client, in case that could expand your integration possibilities]

_________________
_good things come to those who wait(0)_


Top
 Profile  
 
 Post subject:
PostPosted: January 19th, 2009, 10:35 am 
Offline

Joined: May 24th, 2007, 11:02 am
Posts: 132
Location: UK - Wales - Ceredigion
Opus: illuminatus > Evolution
OS: Windows 10 Pro
System: i7 8GB RAM
Thank you for your reply.

Here is an example of what I need.

- Lets say I use testSwitch(1,4) this should return 1
- There are only two x examples, but there would be lots more
- The values of y need to be changable by the end user when they needed. They would be able to do this if the external script was a .txt file
- This could aslo be written as a Switch, but for now I am using IF statements.

Code:
function testSwitch(x,y) {

    //testSwitch returns 1 if any match
   
if (x == "1"){   
  if(y == "1" || y == "2" || y == "3" || y == "4" || y == "5" || y == "6" || y == "7" ){
i=1;      
  }
}

if (x == "2"){   
  if(y == "4" || y == "5" || y == "7" || y == "9" || y == "15" || y == "26" || y == "27" ){
i=1;      
  }
}

//return the value of i
return i;
}


Top
 Profile Visit website  
 
 Post subject:
PostPosted: January 19th, 2009, 10:53 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Hi Jez,

Executing an external script is not possible. You can simulate some effect using the the eval() function, but remember that you are then allowing your program to execute somebody else's unchecked code. If the wrong or malicious script was included - then running the program you have designed might cause serious damage.

Although your x & y values change you don't state whether the actual function structure changes. For example, is the function simply a check of x value and then if true a check of a list of y values. This process being repeated for several values of x.

If this is the case, then you could read the x, y into Opus via a txt or ini and use a dynamic loop to check.

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject:
PostPosted: January 19th, 2009, 11:53 pm 
Offline

Joined: March 8th, 2005, 9:40 pm
Posts: 63
Hi Jez,

I'm a bit slow, so humour me...

Also in the the explanation I have tried to be quite detailed and this is not meant to insult your knowledge, but to possibly help others in the future!

Are you wanting to compare values x & y inputted by the user, to predefined x to (many possible) y values that were inputted by your client?

i.e. The user inputs x=3 and y=23 in a text input box (for example) and you want to check if x3 contains a value of 23, predefined by your client?

If so an ini file could solve your problem
Create an ini file called xydata.ini in the same directory that you have saved the attached TestInput.imp file containing the following text. (You can do this by opening notepad, and paste the following code and save it as xydata.ini)

Code:
[x1]
y=1,2,3,4
[x2]
y=5,6,7,8
[x3]
y=9,10,11,12


Then run the attached imp file.
If the user input, lets say x=2 and y=6, matches the client ini file input you get a 1, else you get a 0 in the "true" txt box.

If this solves your problem, all your client would need to do is create the ini file with [x1] to [x(a)], with (a) being the last value required for x and all the possible y values for each [x(a)] value.

I hope I have understood your question, explained this properly and that it helps... :)

If not, perhaps you could post a simple example imp file of what you want to achieve. :roll:

Normally forum members will help you with tips, but like you to think about your problems, to encourage you to learn. As I am also a novice at Opusscript, I did this as a learning exercise for myself. :idea:

Check my "tips for posting" in the basics section. :wink:

Regards

Nitro


You do not have the required permissions to view the files attached to this post.

_________________
Opus Pro V6
Dell Inspiron 9400
Intel Centrino Duo 2GHz
2 Gig Ram
XP SP2


Top
 Profile  
 
 Post subject: Using external variables in an .ini file
PostPosted: January 20th, 2009, 1:31 pm 
Offline

Joined: May 24th, 2007, 11:02 am
Posts: 132
Location: UK - Wales - Ceredigion
Opus: illuminatus > Evolution
OS: Windows 10 Pro
System: i7 8GB RAM
Wow Nitro! That's great. I've been able to adapt what you wrote and it's solved my problem - thank you.

And thank you to mackavi and Lar_123 for your replies too


Top
 Profile Visit website  
 
 Post subject:
PostPosted: January 20th, 2009, 9:42 pm 
Offline

Joined: March 8th, 2005, 9:40 pm
Posts: 63
I actually have to thank Mack, He was the one that helped me learn to script and explained the benefits of ini files and how they work.

I also think that this can also be developed to be used in a test type situation when there are several correct answers to a question and the client has to be able to change the questions and answers, without developer intervention. To make this more secure, two separate programmes could be used, one to make the questions and answers (and encrypt them) and the test programme that decrypts and checks the answers from the ini file.

Regards

Nitro

_________________
Opus Pro V6
Dell Inspiron 9400
Intel Centrino Duo 2GHz
2 Gig Ram
XP SP2


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 42 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group