ยินดีต้อนรับแขกผู้มาเยือน กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน
ส่งอีเมล์ยืนยันการใช้งาน?
 
Please Login!

ผู้เขียน หัวข้อ: การเขียน Script Action Wizard & Plugin ใน AutoPlay Media Studio 7, 8 (ภาค3)  (อ่าน 9707 ครั้ง)

0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้

ออฟไลน์ sak2005

  • สมาชิกกิตติมศักดิ์
  • *
  • โพสต์: 1,934
  • คูลเฟิร์ม: 7826
  • zula: 3653.25
  • เพศ: ชาย
    • ดูรายละเอียด
  • ตำแหน่ง:ครูผู้ให้

  • ล็อคอิน @ วันนี้ เวลา 07:48:54
Re: การเขียน Script Action Wizard & Plugin ใน AutoPlay Media Studio 7, 8 (ภาค3)
« ตอบกลับ #20 เมื่อ: 19 พฤศจิกายน 2011, 02:19:29 »
ถามไรหน่อยครับ  จะติดตั้งโปรแกรม แต่โปรแกรมมี crack ด้วย  การลง crack ต้องทำไงให้ไฟล์ไปอยู่ที่ที่  โปรแกรมติดตั้งลงไปครับ ...

การcrack มีหลายวิธี และ Crack ที่จัดทำขึ้นก็มีอยู่หลายชนิด

แต่ถ้าเป็นชนิด Path.exe จะต้องนำ  Path.exe เข้าไปรันใน Directory หรือ Target ของโปรแกรม

คำถามที่วา่..การลง crack ต้องทำไงให้ไฟล์ไปอยู่ที่ที่  โปรแกรมติดตั้งลงไป

ตอบว่า.. ต้องมีพื้นฐานการเขียนคำสั่งภาษาคอมพิวเตอร์ ถึงจะทำได้ (Basic Programming)






Coolfirmed by (1)สมาชิก:
จำเป็นต้องใช้ FlashPlayer

คำคม: เมื่อเวลาเปลี่ยน.. ทุกอย่างเปลี่ยน..

ออฟไลน์ 6สูงเต็งสูง

  • นักศึกษา
  • *
  • โพสต์: 275
  • คูลเฟิร์ม: 568
  • zula: 276.5
  • เพศ: ชาย
    • ดูรายละเอียด
  • TKK_OS

  • ล็อคอิน @ เมื่อวานนี้ เวลา 16:35:30
Re: การเขียน Script Action Wizard & Plugin ใน AutoPlay Media Studio 7, 8 (ภาค3)
« ตอบกลับ #21 เมื่อ: 19 พฤศจิกายน 2011, 15:59:13 »
 ;) ;) ผมติดอยู่ที่ โปรแกรม  Microsoft office มันมีคีย์ให้ใส่ด้วย  เราต้องไปทำ Auto มันก่อนหรือยังไงครับ ท่าน  ผมเพิ่งลองเล่น ต้องใช้โปรแกรมอะไร
Coolfirmed by (1)สมาชิก:

ออฟไลน์ sak2005

  • สมาชิกกิตติมศักดิ์
  • *
  • โพสต์: 1,934
  • คูลเฟิร์ม: 7826
  • zula: 3653.25
  • เพศ: ชาย
    • ดูรายละเอียด
  • ตำแหน่ง:ครูผู้ให้

  • ล็อคอิน @ วันนี้ เวลา 07:48:54
Re: การเขียน Script Action Wizard & Plugin ใน AutoPlay Media Studio 7, 8 (ภาค3)
« ตอบกลับ #22 เมื่อ: 20 พฤศจิกายน 2011, 04:36:29 »
;) ;) ผมติดอยู่ที่ โปรแกรม  Microsoft office มันมีคีย์ให้ใส่ด้วย  เราต้องไปทำ Auto มันก่อนหรือยังไงครับ ท่าน  ผมเพิ่งลองเล่น ต้องใช้โปรแกรมอะไร

ท่านต้องทำ Microsoft office ให้เป็น Package Setup ก่อน โดยพิมพ์คำสั่งลงไปในช่อง RUN ดังนี้.. SETUP.EXE /a

..จากนั้นก็กำหนดให้ติดตั้งไว้ที่ไดร์ฟ C:\  ..ใส่ Serial Number และติดตั้งไปตามปกติ ท่านก็จะได้ Package Setup ไว้ใช้งาน

โดยที่ท่านไม่ต้องคอยใส่ Serial Number อีก ..จริงๆแล้วอยากจะลง Package Setup ให้ดาวน์โหลดกัน แต่ติดเรื่องลิขสิทธิ์



 
Coolfirmed by (2)สมาชิก:
« แก้ไขครั้งสุดท้าย: 20 พฤศจิกายน 2011, 05:16:24 โดย sak2005 »
จำเป็นต้องใช้ FlashPlayer

คำคม: เมื่อเวลาเปลี่ยน.. ทุกอย่างเปลี่ยน..

ออฟไลน์ sak2005

  • สมาชิกกิตติมศักดิ์
  • *
  • โพสต์: 1,934
  • คูลเฟิร์ม: 7826
  • zula: 3653.25
  • เพศ: ชาย
    • ดูรายละเอียด
  • ตำแหน่ง:ครูผู้ให้

  • ล็อคอิน @ วันนี้ เวลา 07:48:54
Re: การเขียน Script Action Wizard & Plugin ใน AutoPlay Media Studio 7, 8 (ภาค3)
« ตอบกลับ #23 เมื่อ: 20 พฤศจิกายน 2011, 12:42:22 »
Control Structures

Control Structures เป็นคำสั่งที่ใช้สำหรับควบคุมการทำงานของโปรแกรมให้อยู่ในขอบเขต ด้วย เงื่อนไข!? หรือการทำงานซ้ำๆ มีดังนี้

1.If
An if statement evaluates its condition and then only executes the “then” part if the
condition is true. An if statement is terminated by the “end” keyword. The basic
syntax is:
if condition then
  do something here
end
For example:
x = 50;
if x > 10 then
    Dialog.Message("result", "x is greater than 10");
end
 
y = 3;
if ((35 * y) < 100) then
    Dialog.Message("", "y times 35 is less than 100");
end
In the above script, only the first dialog message would be shown, because the second
if condition isn't true...35 times 3 is 105, and 105 is not less than 100.
You can also use else and elseif to add more “branches” to the if statement:
x = 5;
if x > 10 then
    Dialog.Message("", "x is greater than 10");
else
    Dialog.Message("", "x is less than or equal to 10");
end
In the preceding example, the second dialog message would be shown, because 5 is
not greater than 10.
-------------------------------------------------------------------------------------------------
2.While
The while statement is used to execute the same “block” of script over and over un
condition is met. Like if statements, while statements are terminated with the “end
keyword. The basic syntax is:
while condition do
  do something here
end
The condition must be true in order for the actions inside the while statement (the
something here” part above) to be performed. The while statement will continue to
loop as long as this condition is true. Here's how it works:
If the condition is true, all of the actions between the “while” and the correspondin
“end” will be performed. When the “end” is reached, the condition will be
reevaluated, and if it's still true, the actions between the “while” and the “end” will
performed again. The actions will continue to loop like this until the condition
evaluates to false.
For example:
a = 1;
while a < 10 do
    a = a + 1;
end
In the preceding example, the “a = a + 1;” line would be performed 9 times. 
----------------------------------------------------------------------------------------
3.Repeat
The repeat statement is similar to the while statement, except that the condition is
checked at the end of the structure instead of at the beginning. The basic syntax is:
repeat
  do something here
until condition
For example:
i = 1;
repeat
    i = i + 1;
until i > 10
This is similar to one of the while loops above, but this time, the loop is performed 10
times. The “i = i + 1;” part gets executed before the condition determines that i is now
larger than 10.
----------------------------------------------------------------------------------------------------
4.For
The for statement is used to repeat a block of script a specific number of times. The
basic syntax is:
for variable = start, end, step do
  do something here
end
The variable can be named anything you want. It is used to “count” the number of
trips through the for loop. It begins at the start value you specify, and then changes by
the amount in step after each trip through the loop. In other words, the step gets added
to the value in the variable after the lines between the for and end are performed. If
the result is smaller than or equal to the end value, the loop continues from the
beginning.
For example:
-- This loop counts from 1 to 10:
for x = 1, 10 do
    Dialog.Message("Number", x);
end
This displays 10 dialog messages in a row, counting from 1 to 10.
Note that the step is optional; if you don’t provide a value for the step, it defaults to 1.
Coolfirmed by (1)สมาชิก:
« แก้ไขครั้งสุดท้าย: 20 พฤศจิกายน 2011, 19:50:24 โดย sak2005 »
จำเป็นต้องใช้ FlashPlayer

คำคม: เมื่อเวลาเปลี่ยน.. ทุกอย่างเปลี่ยน..

ออฟไลน์ sak2005

  • สมาชิกกิตติมศักดิ์
  • *
  • โพสต์: 1,934
  • คูลเฟิร์ม: 7826
  • zula: 3653.25
  • เพศ: ชาย
    • ดูรายละเอียด
  • ตำแหน่ง:ครูผู้ให้

  • ล็อคอิน @ วันนี้ เวลา 07:48:54
Re: การเขียน Script Action Wizard & Plugin ใน AutoPlay Media Studio 7, 8 (ภาค3)
« ตอบกลับ #24 เมื่อ: 20 พฤศจิกายน 2011, 20:10:01 »
Tables (Arrays)

Tables are very useful. They can be used to store any type of value, even including
functions or other tables.

Tables Array คือรูปแบบมิติของข้อมูลที่สร้างขึ้น ใช้เครื่องหมาย { } หรือ ปีกกา เปิด - ปิด

การสร้างอาร์เรย์ (Array)

Creating Tables
There are generally two ways to create a table from scratch. The first
braces to specify a list of values:
my_table = {"apple","orange","peach"};
associative_table = {fruit="apple", vegetable="carr
my_table = {};
my_table[1] = "apple";
my_table[2] = "orange";
my_table[3] = "peach";
 
associative_table = {};
associative_table.fruit = "apple";
associative_table.vegetable = "carrot";
--------------------------------------------
Accessing Table Elements
Each “record” of information stored in a table is known as an element. Each element
consists of a key, which serves as the index into the table, and a value that is
associated with that key.
There are generally two ways to access an element: you can use array notation, or dot
notation. Array notation is typically used with numeric arrays, which are simply tables
where all of the keys are numbers. Dot notation is typically used with associative
arrays, which are tables where the keys are strings.
Here is an example of array notation:
t = {"one", "two", "three"};
Dialog.Message("Element one contains:", t[1]);
Here is an example of dot notation:
t = {first="one", second="two", third="three"};
Dialog.Message("Element 'first' contains:", t.first);
-----------------------------------------------------------
อาร์เรย์ แบ่งออกเป็นชนิดต่างๆ ดังนี้

1. Numeric Arrays
One of the most common uses of tables is as arrays. An array is a collection of val
that are indexed by numeric keys. In the scripting engine, numeric arrays are one-
based. That is, they start at index 1.
Here are some examples using numeric arrays:
Example 1:
myArray = {255,0,255};
Dialog.Message("First Number", myArray[1]);
This first example would display a dialog message containing the number “255.”

 Example 2:
alphabet = {"a","b","c","d","e","f","g","h","i","j","k",
"l","m","n","o","p","q","r","s","t","u","v","w","x","y","
Dialog.Message("Seventh Letter", alphabet[7]);
This would display a dialog message containing the letter “g.”
Example 3:
myArray = {};
myArray[1] = "Option One";
myArray[2] = "Option Two";
myArray[3] = "Option Three";
This is exactly the same as the following:
myArray = {"Option One", "Option Two", "Option Three"};

2. Associative Arrays
Associative arrays are the same as numeric arrays except that the indexes can be
numbers, strings or even functions.
Here is an example of an associative array that uses a last name as an index and a first
name as the value:
arrNames = {Anderson="Jason",
            Clemens="Roger",
            Contreras="Jose",
            Hammond="Chris",
            Hitchcock="Alfred"};
 
Dialog.Message("Anderson's First Name", arrNames.Anderson);

Here is an example of a simple employee database that keeps track of employee
names and birth dates indexed by employee numbers:
Employees = {}; -- Construct an empty table for the employee numbers
 
-- store each employee's information in its own table
Employee1 = {Name="Jason Anderson", Birthday="07/02/82"};
Employee2 = {Name="Roger Clemens", Birthday="12/25/79"};
 
-- store each employee's information table
-- at the appropriate number in the Employees table
Employees[100099] = Employee1;
Employees[137637] = Employee2;
 
-- now typing "Employees[100099]" is the same as typing "Employee1"
Dialog.Message("Birthday",Employees[100099].Birthday);
--------------------------------------------------------------------------------------
Using For to Enumerate Tables

There is a special version of the for statement that allows you to quickly and easily
enumerate the contents of an array. The syntax is:

for index,value in table do
  operate on index and value
end

For example:
mytable = {"One","Two","Three"};
 
-- display a message for every table item
for j,k in mytable do
    Dialog.Message("Table Item", j .. "=" .. k);
end

 
If you just want the indexes of a table, you can leave out the value part of the for
statement:
a = {One=1, Two=2, Three=3};
 
for k in a do
    Dialog.Message("Table Index", k);
end
The above script will display three message boxes in a row, with the text “One,”
“Three,” and then “Two.”
Whoa there—why aren’t the table elements in order? The reason for this is that
internally the scripting engine doesn’t store tables as arrays, but in a super-efficient
structure known as a hash table. The important thing to know is that when you define
table elements, they are not necessarily stored in the order that you define or add
them, unless you use a numeric array (i.e. a table indexed with numbers from 1 to
whatever).
----------------------------------------------------------------------------------------------------
Copying Tables
Copying tables is a bit different from copying other types of values. Unlike variables,
you can't just use the assignment operator to copy the contents of one table into
another. This is because the name of a table actually refers to an address in memory
where the data within the table is stored. If you try to copy one table to another using
the assignment operator, you end up copying the address, and not the actual data.
For example, if you wanted to copy a table, and then modify the copy, you might try
something like this:
table_one = { mood="Happy", temperature="Warm" };
 
-- create a copy
table_two = table_one;
 
-- modify the copy
table_two.temperature = "Cold";
 
Dialog.Message("Table one temperature is:", table_one.temperature);
Dialog.Message("Table two temperature is:", table_two.temperature);

Luckily, the for statement makes this really easy to do. For example, here’s a modified
version of our earlier example, that creates a “true” copy of table_one.
table_one = { mood="Happy", temperature="Warm" };
 
-- create a copy
table_two = {};
for index, value in table_one do
    table_two[index] = value;
end
 
-- modify the copy
table_two.temperature = "Cold";
 
Dialog.Message("Table one temperature is:", table_one.temperature);
Dialog.Message("Table two temperature is:", table_two.temperature);
This time, the dialogs show that modifying table_two doesn’t affect table_one at all:
-------------------------------------------------------------------------------------------------
Table Actions

There are a number of table-related actions at your disposal, which you can use to do
such things as inserting elements into a table, removing elements from a table, and
counting the number of elements in a table. For more information on these actions,
please see Program Reference / Actions / Table in the online help.
 
Coolfirmed by (1)สมาชิก:
« แก้ไขครั้งสุดท้าย: 23 พฤศจิกายน 2011, 00:02:45 โดย sak2005 »
จำเป็นต้องใช้ FlashPlayer

คำคม: เมื่อเวลาเปลี่ยน.. ทุกอย่างเปลี่ยน..

ออฟไลน์ sak2005

  • สมาชิกกิตติมศักดิ์
  • *
  • โพสต์: 1,934
  • คูลเฟิร์ม: 7826
  • zula: 3653.25
  • เพศ: ชาย
    • ดูรายละเอียด
  • ตำแหน่ง:ครูผู้ให้

  • ล็อคอิน @ วันนี้ เวลา 07:48:54
Re: การเขียน Script Action Wizard & Plugin ใน AutoPlay Media Studio 7, 8 (ภาค3)
« ตอบกลับ #25 เมื่อ: 21 พฤศจิกายน 2011, 14:00:46 »
คำตอบที่หลายท่านถามมาว่า.. 'อาจารย์ ทำอย่างไร? ที่สามารถเรียนรู้ programming ได้หลายๆภาษา ได้อย่างรวดเ็้ร็ว'

อาจารย์ขอตอบง่ายๆว่า.. ที่จริงแล้ว Programmer ไม่ได้เป็นกันได้ง่ายๆ ถ้าผู้นั้น ไม่มี ใจรัก - อดทน หรือ พรแสวง

พรสวรรค์ เป็นเพียง ความคิดส่วนประกอบ ที่ได้มาจาก บรรพบุรุษเท่านั้น

อาจารย์ศึกษาผ่านมา 8 ปี แล้ว แต่ยังคงต้องศึกษาเพิ่มเติมกันต่อไป ไม่มีวันสิ้นสุด

' ความรู้ ' เมื่อเปรียบเทียบแล้ว คล้ายกับ ต้นไม้ ถ้าต้นไม่ตายซะก่อน มันจะแตกใบ กิ่งก้าน สาขา ออกมาใหม่เรื่อยๆ

Coolfirmed by (3)สมาชิก:
จำเป็นต้องใช้ FlashPlayer

คำคม: เมื่อเวลาเปลี่ยน.. ทุกอย่างเปลี่ยน..

ออฟไลน์ sak2005

  • สมาชิกกิตติมศักดิ์
  • *
  • โพสต์: 1,934
  • คูลเฟิร์ม: 7826
  • zula: 3653.25
  • เพศ: ชาย
    • ดูรายละเอียด
  • ตำแหน่ง:ครูผู้ให้

  • ล็อคอิน @ วันนี้ เวลา 07:48:54
Re: การเขียน Script Action Wizard & Plugin ใน AutoPlay Media Studio 7, 8 (ภาค3)
« ตอบกลับ #26 เมื่อ: 23 พฤศจิกายน 2011, 00:07:06 »
Functions

การเขียนคำสั่งออกมาเป็นรูปแบบฟังก์ชั่น ถือว่าเป็นหัวใจในการ Programjming สำหรับคนที่เป็น Programmer

เพราะจะทำให้ไม่สับสน ในการเขียนคำสั่งและสามารถตรวจสอบ ตรวจทานคำสั่งหรือโค๊ดต่างๆที่เขียนได้ง่ายขึ้น

ในกรณีย์ทีจำเป็นต้องแก้ไขคำสั่งเพิ่มเติม หรือ แก้ไขคำสั่งที่มีข้อผิดพลาด ฉนั้น..ควรหัดเขียนคำสั่งแบบฟังก์ชั่นกันให้ได้

By far the coolest and most powerful feature of the scripting engine is functions.
Functions are simply portions of script that you can define, name and then execute (or
“call”) from anywhere else.
In general, functions are defined as follows:
function function_name (arguments)
  function script here
  return return_value;
end
The first part is the keyword “function.” This tells the scripting engine that what
follows is a function definition. The function_name is simply a unique name for your
function. The arguments are parameters (or values) that will be passed to the function
every time it is called. A function can receive any number of arguments from 0 to
infinity (well, not infinity, but don’t get technical on me). The “return” keyword tells
the function to return one or more values back to the script that called it.
The easiest way to learn about functions is to look at some examples. In this first
example, we will make a simple function that shows a message box. It does not take
any arguments and does not return anything.
function HelloWorld()
    Dialog.Message("Welcome","Hello World");
end
Notice that if you put the above script into an event and then try out your application,
nothing happens. Well, that is true and not true. It is true that nothing visible happens,
but the magic is in what you don’t see. When the event is fired and the function script
is executed, the function called “HelloWorld” becomes part of the scripting engine.
That means it is now available to any other script in the rest of the application.
This brings up an important point about scripting in AutoPlay. When making a
function, the function does not get “into” the engine until the function definition is
executed. That means that if you define HelloWorld() in a button’s On Click event,
but that event never gets triggered (because the button is never clicked), the
HelloWorld() function will not exist. That is, you will not be able to call it from
anywhere else.
--------------------------------------------------------------------------------------------------
รูปแบบในการเขียนคำสั่ง Functions

Function Arguments

Let’s take this a bit further and tell the message box which text to display by adding a
parameter to the function.
A parameter is a special variable in the function definition that will be used to
“receive” a value passed into the function. The value that actually gets passed into the
function is known as an argument.
Tip: Programmers often confuse the terms “parameter” and “argument,” so you will
often find parameters referred to as arguments, an vice-versa. This is understandable,
since they both refer to almost the same thing: a value being passed to a function (an
argument), and a local variable that represents the value in the function (a parameter).
function HelloWorld(Message)
    Dialog.Message("Welcome", Message);
end
 
HelloWorld("This is an argument");
Now the message box shows the text that was “passed” to the function. 
In the function definition, “Message” is a local variable that will automatically receive
whatever argument is passed to the function. In the function call, we pass the string
“This is an argument” as the first (and only) argument for the HelloWorld function.
Note: Parameter variables are always local to the function.
-------------------------------------------------------------------
Returning Values

The next step is to make the function return values back to the calling script. Here is a
function that accepts a number as its single argument, and then returns a string
containing all of the numbers from one to that number.
function Count(n)
 
    -- start out with a blank return string
    ReturnString = "";
 
    for num = 1,n do
        -- add the current number (num) to the end of the return string
        ReturnString = ReturnString..num;
 
        -- if this isn't the last number, then add a comma and a space
        -- to separate the numbers a bit in the return string
        if (num ~= n) then
            ReturnString = ReturnString..", ";
        end
    end
 
    -- return the string that we built
    return ReturnString;
end
 
CountString = Count(10);
Dialog.Message("Count", CountString);
--------------------------------------------
Returning Multiple Values

You can return multiple values from functions as well:
function SortNumbers(Number1, Number2)
    if Number1 <= Number2 then
        return Number1, Number2
    else
        return Number2, Number1
    end
end
 
firstNum, secondNum = SortNumbers(102, 100);
Dialog.Message("Sorted", firstNum .. ", " .. secondNum);
The above script creates a function called SortNumbers that takes two arguments (i.e.
has two parameters) and then returns two values. The first value returned is the
smaller number, and the second value returned is the larger one. 
Note that we specify two variables to receive the return values on the second last line.
The last line of the script displays the two numbers in the order they were sorted into
by the function.
-------------------------
Redefining Functions

Another interesting thing about functions is that you can override a previous function
definition simply by re-defining it.
function HelloWorld()
    Dialog.Message("Message","Hello World");
end
 
function HelloWorld()
    Dialog.Message("Message","Hello Earth");
end
 
HelloWorld();
----------------------
Putting Functions in Tables

One really powerful thing about tables is that they can be used to hold functions as
well as other values. This is significant because it allows you to make sure that your
functions have unique names and are logically grouped. (In fact, this is how all of the
AutoPlay actions are implemented: each action category is actually a table containing
the category’s actions.) Here is an example:
-- Make the functions:
function HelloEarth()
    Dialog.Message("Message", "Hello Earth");
end
 
function HelloMoon()
    Dialog.Message("Message", "Hello Moon");
end
 
-- Define an empty table:
Hello = {};
 
-- Assign the functions to the table:
Hello.Earth = HelloEarth;
Hello.Moon = HelloMoon;
 
-- Now call the functions:
Hello.Earth();
Hello.Moon();
It is also interesting to note that you can define functions right in your table definition:
Hello = {
Earth = function () Dialog.Message("Message", "Hello Earth") end,
 Moon = function () Dialog.Message("Message", "Hello Moon") end 
};
 
-- Now call the functions:
Hello.Earth();
Hello.Moon(); 
Coolfirmed by (1)สมาชิก:
« แก้ไขครั้งสุดท้าย: 23 พฤศจิกายน 2011, 10:52:24 โดย sak2005 »
จำเป็นต้องใช้ FlashPlayer

คำคม: เมื่อเวลาเปลี่ยน.. ทุกอย่างเปลี่ยน..

ออฟไลน์ sak2005

  • สมาชิกกิตติมศักดิ์
  • *
  • โพสต์: 1,934
  • คูลเฟิร์ม: 7826
  • zula: 3653.25
  • เพศ: ชาย
    • ดูรายละเอียด
  • ตำแหน่ง:ครูผู้ให้

  • ล็อคอิน @ วันนี้ เวลา 07:48:54
Re: การเขียน Script Action Wizard & Plugin ใน AutoPlay Media Studio 7, 8 (ภาค3)
« ตอบกลับ #27 เมื่อ: 23 พฤศจิกายน 2011, 11:09:30 »
String Manipulation

String Manipulation เป็นคำสั่งที่เกี่ยวข้องกับการใช้งานตัวอักษร หรือ ตัวหนังสือ มีดังนี้

-- หรือ ขีด2ขีด ใช้ใส่หน้าข้อความ ที่ใช้เป็น Comment หรือ ข้อความรายละเอียด

.. หรือ จุด2จุด ใช้เชื่อมข้อความกับคำสั่ง , คำสั่งกับคำสั่ง และ ข้อความกับข้อความ

"\r\n" หรือ Line feed ใช้สำหรับ ขึ้นบันทัดใหม่ให้ข้อความ
----------------------------------------------------------------------------------------------
In this section we will briefly cover some of the most common string manipulation
techniques, such as string concatenation and comparisons.
(For more information on the string actions available to you in AutoPlay, see Program
Reference / Actions / String in the online help.)

Concatenating Strings
We have already covered string concatenation, but it is well worth repeating. The
string concatenation operator is two periods in a row (..). For example:
FullName = "Bo".." Derek"; -- FullName is now "Bo Derek"
 
-- You can also concatenate numbers into strings
DaysInYear = 365;
YearString = "There are "..DaysInYear.." days in a year.";
Note that you can put spaces on either side of the dots, or on one side, or not put any
spaces at all. For example, the following four lines will accomplish the same thing:
foo = "Hello " .. user_name;
foo = "Hello ".. user_name;
foo = "Hello " ..user_name;
foo = "Hello "..user_name;
However, you cannot put spaces between the two dots:
foo = "Hello ". .user_name; -- syntax error!

Comparing Strings
Next to concatenation, one of the most common things you will want to do with
strings is compare one string to another. Depending on what constitutes a “match,”
this can either be very simple, or a little bit tricky.
If you want to perform a case-sensitive comparison, then all you have to do is use the
equals operator (==).

For example:
strOne = "Strongbad";
strTwo = "Strongbad";
 
if strOne == strTwo then
    Dialog.Message("Guess what?", "The two strings are equal!");
else
    Dialog.Message("Hmmm", "The two strings are different.");
end
Since the == operator performs a case-sensitive comparison when applied to strings,
the above script will display a message box proclaiming that the two strings are equal.
If you want to perform a case-insensitive comparison, then you need to take advantage
of either the String.Upper or String.Lower action, to ensure that both strings have the
same case before you compare them. The String.Upper action returns an all-uppercase
version of the string it is given, and the String.Lower action returns an all-lowercase
version. Note that it doesn’t matter which action you use in your comparison, so long
as you use the same action on both sides of the == operator in your if statement.

For example:
strOne = "Mooohahahaha";
strTwo = "MOOohaHAHAha";
 
if String.Upper(strOne) == String.Upper(strTwo) then
    Dialog.Message("Guess what?", "The two strings are equal!");
else
    Dialog.Message("Hmmm", "The two strings are different.");
end
In the example above, the String.Upper action converts strOne to
“MOOOHAHAHAHA” and strTwo to “MOOOHAHAHAHA” and then the if
statement compares the results. (Note: the two original strings remain unchanged.)
That way, it doesn’t matter what case the original strings had; all that matters is
whether the letters are the same.
Tip: You could also use a String.CompareNoCase action to perform a case-insensitive
comparison on the original strings.

Counting Characters
If you ever want to know how long a string is, you can easily count the number of
characters it contains. Just use the String.Length action, like so:
twister = "If a wood chuck could chuck wood, how much would...um...";
num_chars = String.Length(twister);
Dialog.Message("That tongue twister has:", num_chars .. " characters!");

Finding Strings:
Another common thing you’ll want to do with strings is to search for one string within
another. This is very simple to do using the String.Find action. 
For example:
strSearchIn = "Isn't it a wonderful day outside?";
strSearchFor = "wonder";
 
-- search for strSearchIn inside strSearchFor
nFoundPos = String.Find(strSearchIn, strSearchFor);
 
if nFoundPos ~= nil then
    -- found it!
    Dialog.Message("Search Result", strSearchFor ..
                   " found at position " .. nFoundPos);
else
    -- no luck
    Dialog.Message("Search Result", strSearchFor.." not found!");
end

Replacing Strings:
One of the most powerful things you can do with strings is to perform a search and
replace operation on them. 
The following example shows how you can use the String.Replace action to replace
every occurrence of a string with another inside a target string:
 
strTarget      = "There can be only one. Only one is allowed!";
strSearchFor   = "one";
strReplaceWith = "a dozen";
strNewString   = String.Replace( strTarget
                               , strSearchFor
                               , strReplaceWith );
 
Dialog.Message("After searching and replacing:", strNewString);
 
-- create a copy of the target string with no spaces in it
strNoSpaces = String.Replace(strTarget, " ", "");
 
Dialog.Message("After removing spaces:", strNoSpaces);

 
Extracting Strings
There are three string actions that allow you to “extract” a portion of a string, rather
than copying the entire string itself. These actions are String.Left, String.Right, and
String.Mid.
•  String.Left copies a number of characters from the beginning of the string.
•  String.Right does the same, but counting from the right end of the string
instead.
•  String.Mid allows you to copy a number of characters starting from any
position in the string.
You can use these actions to perform all kinds of advanced operations on strings.
Here’s a basic example showing how they work:
strOriginal = "It really is good to see you again.";
 
-- copy the first 13 characters into strLeft
strLeft = String.Left(strOriginal, 13);
-- copy the last 18 characters into strRight
strRight = String.Right(strOriginal, 18);
 
-- create a new string with the two pieces
strNeo = String.Left .. "awesome" .. strRight .. " Whoa.";
 
-- copy the word "good" into strMiddle
strMiddle = String.Mid(strOriginal, 13, 4);

Converting Numeric Strings into Numbers
There may be times when you have a numeric string, and you need to convert it to a
number.
For example, if you have an input field where the user can enter their age, and you
read in the text that they typed, you might get a value like “31”. Because they typed it
in, though, this value is actually a string consisting of the characters “3” and “1”.
If you tried to compare this value to a number, you would get a syntax error saying
that you attempted to compare a number with a string.
For example, the following script (when placed in the On Startup event):
age = "31";
if age > 18 then
    Dialog.Message("", "You're older than 18.");
end

The problem in this case is the line that compares the contents of the variable “age”
with the number 18:
if age > 18 then
This generates an error because age contains a string, and not a number. The script
engine doesn’t allow you to compare numbers with strings in this way. It has no wa
of knowing whether you wanted to treat age as a number, or treat 18 as a string.
The solution is simply to convert the value of age to a number before comparing it.
There are two ways to do this. One way is to use the String.ToNumber action.
The String.ToNumber action translates a numeric string into the equivalent number
so it can be used in a numeric comparison.
age = "31";
if String.ToNumber(age) > 18 then
    Dialog.Message("", "You're older than 18.");
end
The other way takes advantage of the scripting engine’s ability to convert numbers
into strings when it knows what your intentions are. For example, if you’re
performing an arithmetic operation (such as adding two numbers), the engine will
automatically convert any numeric strings to numbers for you:

age = "26" + 5; -- result is a numeric value
The above example would not generate any errors, because the scripting engine
understands that the only way the statement makes sense is if you meant to use the
numeric string as a number. As a result, the engine automatically converts the numeric
string to a number so it can perform the calculation.
Knowing this, we can convert a numeric string to a number without changing its value
by simply adding 0 to it, like so:
age = "31";
if (age + 0) > 18 then
    Dialog.Message("", "You're older than 18.");
end
In the preceding example, adding zero to the variable gets the engine to convert the
value to a number, and the result is then compared with 18. No more error.

Special Built-in Functions
There are three special built-in functions that may prove useful to you: dofile, require,
and type.
dofile
Loads and executes a script file. The contents of the file will be executed as though it
was typed directly into the script. The syntax is:
dofile(file_path);
For example, say we typed the following script into a file called MyScript.lua (just a
text file containing this script, created with notepad or some other text editor):
Dialog.Message("Hello", "World");
...and we included the file in our AutoPlay project, in the Scripts folder. Wherever the
following line of script is added:
dofile("AutoPlay\\Scripts\\MyScript.lua"));
...that script file will be read in and executed immediately. In this case, you would see
a message box with the friendly “hello world” message.
Tip: Use the dofile function to save yourself from having to re-type or re-paste a
script into your projects over and over again.

require
Loads and runs a script file into the scripting engine. It is similar to dofile except that
it will only load a given file once per session, whereas dofile will re-load and re-run
the file each time it is used. The syntax is:
require(file_path);
So, for example, even if you do two requires in a row:
require("AutoPlay\\Scripts\\foo.lua");
require("AutoPlay\\Scripts\\foo.lua"); -- this line won't do anything

...only the first one will ever get executed. After that, the scripting engine knows that
the file has been loaded and run, and future calls to require that file will have no
effect.

Since the require function will only load a given script file once per session, it is best
suited for loading scripts that contain only variables and function definitions. Since
variables and function definitions are global by default, you only need to load them
once for them to take effect; repeatedly loading the same function definition would
just be a waste of time.
This makes the require function a great way to load external script libraries from the
various events in a project. Every script that needs a function from an external file can
safely require() it, and the file will only actually be loaded the first time it’s needed.
type
This function will tell you the type of value contained in a variable. It returns the
string name for the type of value in the variable. Valid return values are “nil,”
“number,” “string,” “boolean,” “table,” or “function.”
For example:
a = 989;
strType = type(a); -- sets strType to "number"
 
a = "Hi there";
strType = type(a); -- sets strType to "string"
The type function is especially useful when writing your own functions that need to
work with certain data types. For example, the following function uses type() to make
sure that both of its arguments are numbers:

-- find the maximum of two numbers
function Max(Number1, Number2)
    -- make sure both arguments are numeric
    if (type(Number1) ~= "number") or (type(Number2) ~= "number") then
        Dialog.Message("Error", "Please enter numbers");
        return nil; -- we're using nil to indicate an error condition
    else
        if Number1 >= Number2 then
            return Number1;
        else
            return Number2;
        end
    end
end
-------------------------------------------------------
 คำแนะนำ: การเรียนรู้ที่ถูกต้อง ไม่จำเป็นต้องเรียนรู้คำสั่งในคราวเดียวทั้งหมด

เลือกเรียนเฉพาะที่ต้องนำมาใช้งานก็พอ ที่เหลือก็ค่อยๆเรียนรู้ในภายหลังได้
 
Coolfirmed by (1)สมาชิก:
« แก้ไขครั้งสุดท้าย: 25 พฤศจิกายน 2011, 09:30:27 โดย sak2005 »
จำเป็นต้องใช้ FlashPlayer

คำคม: เมื่อเวลาเปลี่ยน.. ทุกอย่างเปลี่ยน..

ออฟไลน์ sak2005

  • สมาชิกกิตติมศักดิ์
  • *
  • โพสต์: 1,934
  • คูลเฟิร์ม: 7826
  • zula: 3653.25
  • เพศ: ชาย
    • ดูรายละเอียด
  • ตำแหน่ง:ครูผู้ให้

  • ล็อคอิน @ วันนี้ เวลา 07:48:54
Re: การเขียน Script Action Wizard & Plugin ใน AutoPlay Media Studio 7, 8 (ภาค3)
« ตอบกลับ #28 เมื่อ: 27 พฤศจิกายน 2011, 08:27:12 »
AMS LUA Script  Example

อันเนื่องมาจากอาจารย์ยังหา LUA Editor ที่ใช้สำหรับรันทดสอบสคริ๊ป Lua ที่เขียนโดยตรงยังไม่ได้

ต้องรันผ่านโปรแกรม AMS ไปก่อน ถ้าเจอ LUA Editor ที่เหมาะสม จะนำมาลงให้
------------------------------------------------------------------------------------------------------
วิธีรันทดสอบสคริ๊ป LUA แบบง่ายๆ ให้ท่านสร้าง AMS Form Design ขึ้นมา จากนั้นใส่ปุ่มลงไปบน Form 1 ปุ่ม

ดับเบิ้ลคลิ๊กที่ปุ่ม และ เปิดใช้งาน  Editor Actions Wizard เขียนสคริ๊ปคำสั่งลงไป
------------------------------------------------------------------------------------------
Operating System Facilities

This library is implemented through table os.

os.clock ()

Returns an approximation of the amount in seconds of CPU time used by the program.

os.date ([format [, time]])

Returns a string or a table containing date and time, formatted according to the given string format.

If the time argument is present, this is the time to be formatted (see the os.time function for a description of this value). Otherwise, date formats the current time.

If format starts with '!', then the date is formatted in Coordinated Universal Time. After this optional character, if format is the string "*t", then date returns a table with the following fields: year (four digits), month (1--12), day (1--31), hour (0--23), min (0--59), sec (0--61), wday (weekday, Sunday is 1), yday (day of the year), and isdst (daylight saving flag, a boolean).

If format is not "*t", then date returns the date as a string, formatted according to the same rules as the C function strftime.

When called without arguments, date returns a reasonable date and time representation that depends on the host system and on the current locale (that is, os.date() is equivalent to os.date("%c")).

os.difftime (t2, t1)

Returns the number of seconds from time t1 to time t2. In POSIX, Windows, and some other systems, this value is exactly t2-t1.

os.execute ([command])

This function is equivalent to the C function system. It passes command to be executed by an operating system shell. It returns a status code, which is system-dependent. If command is absent, then it returns nonzero if a shell is available and zero otherwise.

os.exit ()

Calls the C function exit, with an optional code, to terminate the host program. The default value for code is the success code.

os.getenv (varname)

Returns the value of the process environment variable varname, or nil if the variable is not defined.

os.remove (filename)

Deletes the file or directory with the given name. Directories must be empty to be removed. If this function fails, it returns nil, plus a string describing the error.

os.rename (oldname, newname)

Renames file or directory named oldname to newname. If this function fails, it returns nil, plus a string describing the error.

os.setlocale (locale [, category])

Sets the current locale of the program. locale is a string specifying a locale; category is an optional string describing which category to change: "all", "collate", "ctype", "monetary", "numeric", or "time"; the default category is "all". The function returns the name of the new locale, or nil if the request cannot be honored.

If locale is the empty string, the current locale is set to an implementation-defined native locale. If locale is the string "C", the current locale is set to the standard C locale.

When called with nil as the first argument, this function only returns the name of the current locale for the given category.

os.time ()

Returns the current time when called without arguments, or a time representing the date and time specified by the given table. This table must have fields year, month, and day, and may have fields hour, min, sec, and isdst (for a description of these fields, see the os.date function).

The returned value is a number, whose meaning depends on your system. In POSIX, Windows, and some other systems, this number counts the number of seconds since some given start time (the "epoch"). In other systems, the meaning is not specified, and the number returned by time can be used only as an argument to date and difftime.

os.tmpname ()

Returns a string with a file name that can be used for a temporary file. The file must be explicitly opened before its use and explicitly removed when no longer needed.



Coolfirmed by (1)สมาชิก:
« แก้ไขครั้งสุดท้าย: 28 พฤศจิกายน 2011, 18:41:47 โดย sak2005 »
จำเป็นต้องใช้ FlashPlayer

คำคม: เมื่อเวลาเปลี่ยน.. ทุกอย่างเปลี่ยน..

ออฟไลน์ sak2005

  • สมาชิกกิตติมศักดิ์
  • *
  • โพสต์: 1,934
  • คูลเฟิร์ม: 7826
  • zula: 3653.25
  • เพศ: ชาย
    • ดูรายละเอียด
  • ตำแหน่ง:ครูผู้ให้

  • ล็อคอิน @ วันนี้ เวลา 07:48:54
Re: การเขียน Script Action Wizard & Plugin ใน AutoPlay Media Studio 7, 8 (ภาค3)
« ตอบกลับ #29 เมื่อ: 01 ธันวาคม 2011, 16:57:20 »
ความรู้เกี่ยวกับ Action Wizard ของ From ที่ Event On Timer

หลายท่าน งง!? กับคำสั่งตรงนี้ ถ้าใส่ Action Wizard ลงบน Event ต่างๆอย่างไม่ถูกต้อง ก็จะเกิด Error! ไม่สามารถทำงานได้

อาจารย์จึงขอทบทวนให้อีกครั้งหนึ่ง เพื่อที่ท่านจะได้ใช้ คำสั่งที่เป็น Timer บน Event Form ได้อย่างถูกต้อง

และข้อให้ปฏิบัติตามนี้

1.ห้ามเขียนคำสั่ง Action Wizard  Page.StartTimer ลงบน Form Event.. On Timer

เพราะจะทำให้คำสั้งที่เขียนลงไปนั้น อาจทำงานไม่ถูกต้อง หรือ เกิด Error!

ให้เลือกเขียนไว้ที่ Event อื่นๆ เช่น  Form Event.. On Load เป็นต้น

เหตุที่เป็นเช่นนี้เพราะว่า คำสั่ง Timer ต้องทำงานก่อนคำสั่งอื่น

ไม่งั้นจะไม่สามารถใช้เวลาในการควบคุมการทำงานแบบซ้ำๆได้

2.เขียนคำสั่งAction Wizard หรือ คำสั่ง Lua อื่น ที่ใช้งานร่วมกับ Timer

ให้เขียนไว้บน Form Event.. On Timer ..จะทำให้คำสั่งนั้นๆ

ทำงานตามวงรอบของ Timer ที่ตั้งเวลาไว้ (Interval) หรือ ทำงานซ้ำๆตามระยะเวลาที่กำหนด.
------------------------------------------------------------------------------------------------
มาลองดูกับตัวอย่างคำสั่ง Lua ที่เกี่ยวข้องกับ.. วันเวลา ..นั่นก็คือคำสั่ง.. os.date()

ให้ท่านสร้าง Form ขึ้นมา แล้วใส่ Label ลงไป จากนั้น เขียนคำสั่งลงไปดังนี้

ที่ Form Event.. On Load ใส่คำสั่ง..  Page.StartTimer(1000); ลงไป

ที่ Form Event.. On Timer ใส่คำสั่ง.. Label.SetText("Label1", os.date()); ลงไป

ลอง Preview ดูครับ จะเห็นได้ว่า เวลาจะถูกอัพเดท หรือ ตัวเลขจะเปลี่ยนไปทุกๆ 1 วินาที (1000 Msec = 1 .Sec )

ไม่เข้าใจตรงไหนต้องโพสท์ถามนะครับ ไม่งั้นก็ไม่รู้กระจ่างแจ้ง ปัญญาก็จะไม่เกิด.

 


Coolfirmed by (1)สมาชิก:
« แก้ไขครั้งสุดท้าย: 02 ธันวาคม 2011, 12:00:48 โดย sak2005 »
จำเป็นต้องใช้ FlashPlayer

คำคม: เมื่อเวลาเปลี่ยน.. ทุกอย่างเปลี่ยน..

ออฟไลน์ sak2005

  • สมาชิกกิตติมศักดิ์
  • *
  • โพสต์: 1,934
  • คูลเฟิร์ม: 7826
  • zula: 3653.25
  • เพศ: ชาย
    • ดูรายละเอียด
  • ตำแหน่ง:ครูผู้ให้

  • ล็อคอิน @ วันนี้ เวลา 07:48:54
Re: การเขียน Script Action Wizard & Plugin ใน AutoPlay Media Studio 7, 8 (ภาค3)
« ตอบกลับ #30 เมื่อ: 02 ธันวาคม 2011, 12:05:20 »
วิธีใช้งานคำสั่ง: Object  Plugin Timer ดาวโหลด: คลิ๊กที่นี่

เรามาลองออกแบบสร้างโปรแกรม Counter Timer ด้วย Object  Plugin Timer กันดูครับ

สร้าง Form ขึ้นมา แล้วใส่ Object.. Input1,2, และ 3

ต่อด้วย Object.. ฺีButton1, 2 และ 3

ตามด้วย Label1, 2 และ 3 ตามรูป

และอีกสิ่งหนึ่งที่ขาดไม่ได้ และ ต้องนำออกมาใช้ก็คือ Object  Plugin Timer ที่ดาวน์โหลดและติดตั้งไว้.

เรียก Object  Plugin Timer ออกมาใช้งานเลยครับ

คลิ๊กที่เมนู Object ..เลือก Plugins ..เลือก Timer ..คลิ๊ก OK ..



ดาวน์โหลด: Sample Project Click here
Coolfirmed by (1)สมาชิก:
« แก้ไขครั้งสุดท้าย: 03 ธันวาคม 2011, 00:21:06 โดย sak2005 »
จำเป็นต้องใช้ FlashPlayer

คำคม: เมื่อเวลาเปลี่ยน.. ทุกอย่างเปลี่ยน..

ออฟไลน์ sak2005

  • สมาชิกกิตติมศักดิ์
  • *
  • โพสต์: 1,934
  • คูลเฟิร์ม: 7826
  • zula: 3653.25
  • เพศ: ชาย
    • ดูรายละเอียด
  • ตำแหน่ง:ครูผู้ให้

  • ล็อคอิน @ วันนี้ เวลา 07:48:54
Re: การเขียน Script Action Wizard & Plugin ใน AutoPlay Media Studio 7, 8 (ภาค3)
« ตอบกลับ #31 เมื่อ: 03 ธันวาคม 2011, 00:48:31 »
อธิบายเพิ่มเติมเกี่ยวกับคำสั่ง Timer

Timer คือ Loop Control ชนิดหนึ่ง ที่ต้องทำงานซ้ำๆ ตามระยะเวลาที่กำหนด (Interval) และทำงานไปเรื่อยๆ ไม่มีจุุดสิ้นสุด

แต่ในความเป็นจริง ต้องการให้มีจุดสิ้นสุด ฉนั้น.. เราจะต้องประกาศตัวแปรที่เป็นค่าเริ่ม เป็น global ไว้เป็น 0 เสมอ

หรือเรียกอีกอย่างหนึ่งว่า Save Start Position โดยประกาศไว้ที่.. ..คลิ๊กที่เมนู Project ..เลือก Global Functions..

ประกาศตัวแปรลงไปดังนี้ ตัวอย่าง เช่น nCount = 0;  เป็นต้น คล้ายกับการใช้งานคำสั่ง while

loop , Do loop เมื่อมีค่าเริ่มต้นแล้ว ก็สามารถกำหนดจุดสิ้นสุดได้ โดยให้นับบวกทบกันเรื่อยๆทีละหนึ่ง เช่น.

ืnCount = nCount + 1 เป็นต้น เมื่อต้องการให้หยุดทำงานตรงไหน ก็ใส่คำสั่งเงื่อนไข if end ลงไป เช่น.

if nCount >= ?!? (เงื่อนไขที่กำหนด)  then ตามด้วยคำสั่งอื่นๆ หรือ คำสั่งที่ให้ Timer หยุดทำงาน





Coolfirmed by (1)สมาชิก:
« แก้ไขครั้งสุดท้าย: 03 ธันวาคม 2011, 07:03:15 โดย sak2005 »
จำเป็นต้องใช้ FlashPlayer

คำคม: เมื่อเวลาเปลี่ยน.. ทุกอย่างเปลี่ยน..

ออฟไลน์ sak2005

  • สมาชิกกิตติมศักดิ์
  • *
  • โพสต์: 1,934
  • คูลเฟิร์ม: 7826
  • zula: 3653.25
  • เพศ: ชาย
    • ดูรายละเอียด
  • ตำแหน่ง:ครูผู้ให้

  • ล็อคอิน @ วันนี้ เวลา 07:48:54
Re: การเขียน Script Action Wizard & Plugin ใน AutoPlay Media Studio 7, 8 (ภาค3)
« ตอบกลับ #32 เมื่อ: 04 ธันวาคม 2011, 01:18:03 »
ความรู้เพิ่มเติมเกี่ยวกับ Table (Array) หรือสร้างชุดข้อมูล (Table) และการกระจายข้อมูลในมิติแบบต่างๆ (Array)

อันนี้เป็นตัวอย่างเทเบิ้ล อาเรย์ พื้นฐานทั่วไป ..ลองใส่โค๊ดนี้ลงใน Button Event.. On Click แล้วลองรันดูครับ.

Example1
โค๊ด: [Select]
Lines = [[Line one.
Line two.
Line three.]];
Dialog.Message("Welcome", Lines);

Example2
โค๊ด: [Select]
Lines = "Line one. \n Line two. \n Line three.";
Dialog.Message("Welcome", Lines);

Example3
โค๊ด: [Select]
Lines = {"Line one.", "Line two.", "Line three."};
Dialog.Message("Welcome", Lines[1].."\n"..Lines[2].."\n"..Lines[3]);


 
Coolfirmed by (1)สมาชิก:
« แก้ไขครั้งสุดท้าย: 04 ธันวาคม 2011, 01:47:57 โดย sak2005 »
จำเป็นต้องใช้ FlashPlayer

คำคม: เมื่อเวลาเปลี่ยน.. ทุกอย่างเปลี่ยน..

ออฟไลน์ sak2005

  • สมาชิกกิตติมศักดิ์
  • *
  • โพสต์: 1,934
  • คูลเฟิร์ม: 7826
  • zula: 3653.25
  • เพศ: ชาย
    • ดูรายละเอียด
  • ตำแหน่ง:ครูผู้ให้

  • ล็อคอิน @ วันนี้ เวลา 07:48:54
Re: การเขียน Script Action Wizard & Plugin ใน AutoPlay Media Studio 7, 8 (ภาค3)
« ตอบกลับ #33 เมื่อ: 04 ธันวาคม 2011, 02:14:42 »
ตัวอย่าง เทเบิ้ล อาเรย์ แบบต่างๆ

Numeric Arrays
Example 1:
โค๊ด: [Select]
myArray = {255,0,255};
Dialog.Message("First Number", myArray[1]);

Example 2:
โค๊ด: [Select]
myArray = {};
myArray[1] = "Line One.";
myArray[2] = "Line Two.";
myArray[3] = "Line Three.";
Dialog.Message("Welcome", myArray[1].."\n".. myArray[2].."\n".. myArray[3])

Example 3:
โค๊ด: [Select]
Lines = {"Line One.", "Line Two.", "Line Three."}; 
Dialog.Message("Welcome", Lines[1].."\n".. Lines[2].."\n".. Lines[3])
Coolfirmed by (1)สมาชิก:
« แก้ไขครั้งสุดท้าย: 04 ธันวาคม 2011, 02:19:54 โดย sak2005 »
จำเป็นต้องใช้ FlashPlayer

คำคม: เมื่อเวลาเปลี่ยน.. ทุกอย่างเปลี่ยน..

ออฟไลน์ หนุ่มดอย

  • นักศึกษา
  • *
  • โพสต์: 142
  • คูลเฟิร์ม: 532
  • zula: 241
    • ดูรายละเอียด

  • ล็อคอิน @ เมื่อวานนี้ เวลา 21:05:03
Re: การเขียน Script Action Wizard & Plugin ใน AutoPlay Media Studio 7, 8 (ภาค3)
« ตอบกลับ #34 เมื่อ: 04 ธันวาคม 2011, 06:34:04 »
ขอบคุณครับจะค่อยๆศึกษาไปครับ
Coolfirmed by (1)สมาชิก:

ออฟไลน์ sak2005

  • สมาชิกกิตติมศักดิ์
  • *
  • โพสต์: 1,934
  • คูลเฟิร์ม: 7826
  • zula: 3653.25
  • เพศ: ชาย
    • ดูรายละเอียด
  • ตำแหน่ง:ครูผู้ให้

  • ล็อคอิน @ วันนี้ เวลา 07:48:54
Re: การเขียน Script Action Wizard & Plugin ใน AutoPlay Media Studio 7, 8 (ภาค3)
« ตอบกลับ #35 เมื่อ: 04 ธันวาคม 2011, 13:09:37 »
วิธีการรันทดสอบคำสั่งภาษา  LUA ด้วย โปรแกรม  lua.exe โดยรันทาง Dos Command Line และ โปรแกรม LUAEdit.exe ซึ่งสั่งรันบน Script Editor

Download:โปรแกรม Lua Script Editor_AutoSetup.exe ( File Size: 4.7 MB) Click here
Download:โปรแกรม Lua Command Editor (File Size: 24 MB) Click here
---------------------------------------------------------------------------------------------------------------------
การเขียนสคริ๊ปคำสั่งจากภาาษาใดๆ ลงบน Editor และทดสอบโค๊ดที่เขียน มีหลักการปฏิบัติ ดังนี้

1.เมื่อเขียนสคริ๊ปคำสั่งนั้นๆออกมาเป็นโค๊ดเรียบร้อยแล้ว ต้อง Save ออกมาเป็นไฟล์สคริ๊ปสกุลนั้นๆก่อน ถึงจะรันทดสอบได้

2.ถ้ามีไฟล์สคริ๊ปสกุลนั้น ที่เขียนอยู่แล้ว ให้ใช้เมนู Open นำสคริ๊ปโค๊ดนั้นเข้ามาใน Editor ก่อน ถึงจะรันทดสอบได้

3.เมื่อมีการแก้ไขหรือเขียนเพิ่มเติม คำสั่ง ใน Editor เมื่อทำเสร็จแล้ว ให้คลิ๊กที่เมนู Save ทุกครั้ง ก่อนรันทดสอบ

4.วิธีรันทดสอบ ให้คลิ๊กที่เมนู Execute เลือก Execute หรือกด F9 จะมีหน้าต่างแสดงผล (Debug Display) ปรากฏขึ้น

คำแนะนำ: ให้หัดออกแบบ (ํYour Idia) เขียนชุดคำสั่งบ่อยๆ จะทำให้ท่านสามารถเรียนรู้ เป็น Advance Programming ได้อย่างรวดเร็ว
Coolfirmed by (1)สมาชิก:
« แก้ไขครั้งสุดท้าย: 05 ธันวาคม 2011, 15:52:39 โดย sak2005 »
จำเป็นต้องใช้ FlashPlayer

คำคม: เมื่อเวลาเปลี่ยน.. ทุกอย่างเปลี่ยน..

ออฟไลน์ sak2005

  • สมาชิกกิตติมศักดิ์
  • *
  • โพสต์: 1,934
  • คูลเฟิร์ม: 7826
  • zula: 3653.25
  • เพศ: ชาย
    • ดูรายละเอียด
  • ตำแหน่ง:ครูผู้ให้

  • ล็อคอิน @ วันนี้ เวลา 07:48:54
Re: การเขียน Script Action Wizard & Plugin ใน AutoPlay Media Studio 7, 8 (ภาค3)
« ตอบกลับ #36 เมื่อ: 05 ธันวาคม 2011, 11:05:43 »
ตัวอย่าง:โค๊ดคำสั่งที่อาจารย์ ใช้ความคิด ออกแบบเขียนขึ้นมาเอง ให้ท่านลองก๊อบปี้ไปวางบน Script editor

จากนั้น Save เป็นไฟล์สกุล .lua แล้วลองรันดูครับ

โค๊ด: [Select]
function DateTime ()
   local DT = {os.date ("%z"), os.date ("%a").."/"..os.date ("%d").."/"..os.date ("%m").."/"..2000+os.date ("%y"), os.date ("%H")..":"..os.date ("%M")..":"..os.date ("%S")};
   print ("Scriptting Design By: sak2005", DT [1], DT [2], DT [3]);
end
 DateTime ()
Coolfirmed by (0)สมาชิก:
 
« แก้ไขครั้งสุดท้าย: 05 ธันวาคม 2011, 14:15:57 โดย sak2005 »
จำเป็นต้องใช้ FlashPlayer

คำคม: เมื่อเวลาเปลี่ยน.. ทุกอย่างเปลี่ยน..

ออฟไลน์ sak2005

  • สมาชิกกิตติมศักดิ์
  • *
  • โพสต์: 1,934
  • คูลเฟิร์ม: 7826
  • zula: 3653.25
  • เพศ: ชาย
    • ดูรายละเอียด
  • ตำแหน่ง:ครูผู้ให้

  • ล็อคอิน @ วันนี้ เวลา 07:48:54
Re: การเขียน Script Action Wizard & Plugin ใน AutoPlay Media Studio 7, 8 (ภาค3)
« ตอบกลับ #37 เมื่อ: 06 ธันวาคม 2011, 08:29:19 »
Associative Arrays

 
โค๊ด: [Select]
print ("                      Programming Design by: sak2005");
local DateTime={tz=os.date ("%z"), da=os.date ("%a").."/"..os.date ("%d").."/"..os.date ("%m").."/"..2000+os.date ("%y"), ti=os.date ("%H")..":"..os.date ("%M")..":"..os.date ("%S")};
print (DateTime.tz, DateTime.da, DateTime.ti);

อธิบาย: DateTime เป็นตัวแปรอาเรย์ (Operate Var Array Return)
           tz , da และ ti เป็น ตัวแปรตัวดำเนินการของข้อมูล (Operate Var Name) ใน Table Elements
           ฉนั้น..ค่าที่ได้ออกมา จะเท่ากับ Var Array ที่มีสกุลเป็น  Var Name เช่นดั่งในโค๊ดก็คือ
           DateTime.tz, DateTime.da, DateTime.ti นั่นเอง ลองหัดเขียนกันดูนะครับ
Coolfirmed by (0)สมาชิก:
 
« แก้ไขครั้งสุดท้าย: 07 ธันวาคม 2011, 01:44:34 โดย sak2005 »
จำเป็นต้องใช้ FlashPlayer

คำคม: เมื่อเวลาเปลี่ยน.. ทุกอย่างเปลี่ยน..

ออฟไลน์ sak2005

  • สมาชิกกิตติมศักดิ์
  • *
  • โพสต์: 1,934
  • คูลเฟิร์ม: 7826
  • zula: 3653.25
  • เพศ: ชาย
    • ดูรายละเอียด
  • ตำแหน่ง:ครูผู้ให้

  • ล็อคอิน @ วันนี้ เวลา 07:48:54
Re: การเขียน Script Action Wizard & Plugin ใน AutoPlay Media Studio 7, 8 (ภาค3)
« ตอบกลับ #38 เมื่อ: 07 ธันวาคม 2011, 10:11:28 »
Enum Table Array Loop

เป็นวิธีกระจายข้อมูล ด้วย คำสั่ง Control Loop ต่างๆ เช่น while, do และ repeat เป็นต้น ลองมาทดสอบกับตัวอย่างคำสั่งแบบง่ายๆกันก่อนครับ

โค๊ด: [Select]
print ("Info: Data in the Table is One, Two, Three, Four and Five");
local mytable = {"One","Two","Three", "Four","Five"};
element = ""
for x = 1, 5 do
   element = element .. mytable[x] .."\n";
end
print ("Discript: Data elements in the Table array is:" .. "\n"  .. element);

-------------------------------------------------------------------------------------------
ใช้คำสั่ง: pairs กระจายข้อมูล

โค๊ด: [Select]
a = {"one","two","three"};  --Table
out = "";  -- global
for k, j in pairs (a) do
out = out.. k .."="..j.."\n";  -- Loop
end
print (out); -- Display
print (" OR");
print ("")
a = {one=1,two=2, three=3};  --Table
out = "";  -- global
for k, j in pairs (a) do
out = out.. k .."="..j.."\n";  -- Loop
end
print (out); -- Display

อธิบาย: คำสั่ง pairs ทำงานคล้ายกับคำสั่ง UBound ที่ใช้ในภาษาอื่นๆ
            ทำหน้าที่ ขยาย หรือ กระจายข้อมูลออกมาทางตัวแปร ArrayName หรือ a
            k คือ index หรือ ตัวนับ เช่นนับ 1 ถึง 3
            j คือ ตัวเลขที่เป็นตัวแปรของข้อมูล (Table elements)
             เมื่อข้อมูลถูก Loop จะได้ข้อมูลออกมา ตามการนับ
---------------------------------------------------------------------------------------------
อันนี้เป็นการกระจายข้อมูลด้วยลูป while และ repeat

โค๊ด: [Select]
a = {"one","two","three"};  -- Table
out = "";  -- global
x = 0; -- save start position
while x < 3  do
x=x+1
out = out..a[x].."\n"; -- Loop
end
print (out); -- Display

-- OR

a = {"one","two","three"};  -- Table
out = "";  -- global
x = 0; -- save start position
repeat
x=x+1
out = out..a[x].."\n"; -- Loop
until x >= 3
print (out); -- Display
---------------------------------------------------
ตัวอย่าง: Numeric Arrays ขยายข้อมูลด้วย Loop

โค๊ด: [Select]
myArray = {}; -- create table
myArray[1] = "LineOne.";
myArray[2] = "LineTwo.";
myArray[3] = "LineThree.";
out="";
for x = 1, 3 do
out=out..myArray[x].."\n"; -- loop
end
print (out); -- display

             
           
Coolfirmed by (0)สมาชิก:
 
« แก้ไขครั้งสุดท้าย: 08 ธันวาคม 2011, 10:27:53 โดย sak2005 »
จำเป็นต้องใช้ FlashPlayer

คำคม: เมื่อเวลาเปลี่ยน.. ทุกอย่างเปลี่ยน..

ออฟไลน์ sak2005

  • สมาชิกกิตติมศักดิ์
  • *
  • โพสต์: 1,934
  • คูลเฟิร์ม: 7826
  • zula: 3653.25
  • เพศ: ชาย
    • ดูรายละเอียด
  • ตำแหน่ง:ครูผู้ให้

  • ล็อคอิน @ วันนี้ เวลา 07:48:54
Re: การเขียน Script Action Wizard & Plugin ใน AutoPlay Media Studio 7, 8 (ภาค3)
« ตอบกลับ #39 เมื่อ: 09 ธันวาคม 2011, 09:42:41 »
Lua Module interfade and Library include

ภาษา Lua เท่าที่ค้นหา ยังไม่มี Form design เป็นของตนเอง มีแต่ script function ต่างๆ ที่ต้องอาศัยรันบน Script Editor
ฉนั้น..จึงไม่สามารถสร้างโปรแกรม(GUI)อะไรออกมาได้ แต่..ถ้าจะเขียนโค๊ดคำสั่งให้ออกมาเป็นโปรแกรม ก็ต้องอาศัยโปรแกรมอื่น (Utilities) และภาษาอื่นๆ ช่วยสนับสนุนการการเขียน เช่น ใช้คำสั่งที่เป็นโมดูล CLRจากภาษา Visual Basic .Net หรือ คำสั่งที่เป็นไลบารี่จากภาษา Visual Basic C# or C++ (Library Include) เรามาลองเขียนโปรแกรมในรูปแบบคำสั่งต่างๆแบบง่ายๆกันดูครับ
-------------------------------------------------------------------------------------------------------------------------------
Lua Module .Net (CLR) GUI
โปรแกรมที่ใช้รันทดสอบ: SciTe Editor v1.75  ของโปรแกรม Lua For Windows
ให้ท่าน Save โค๊ดคำสั่งด้านล่างเป็นไฟล์สกุล .wlua จากนั้นดับเบิ้ลคลิ๊กที่ไฟล์เพื่อรันทดสอบ



โค๊ด: [Select]
-- form3.wlua

require 'CLRPackage'   --include หรืออ้างคำสั่ง CLR Module .Net
import "System.Windows.Forms"  --อ้างคำสั่ง NameSpace
import "System.Drawing"

button = Button()
button.Text = "Button..Click!"
button.Dock = DockStyle.Top        --สร้าง Object และ Properties
edit = RichTextBox()
edit.Text = "This is a RichTextBox."
edit.Dock = DockStyle.Fill

form = Form()
form.Text = "Module CLR Sample"  --สร้าง Form และติดตั้ง Object ลงบนฟอร์ม
form.Controls:Add(edit)
form.Controls:Add(button)

button.Click:Add(function()
MessageBox.Show("Hello World!",arg[0],MessageBoxButtons.OK)  --ฟังชั่นควบคุมการทำงานของปุ่ม
end)

form:ShowDialog()  --คำสั่งที่ทำให้หน้าต่างโปรแกรมปรากฏขึ้น


แนะนำ: ควรศึกษาเกี่ยวกับคำสั่งต่างๆใน Vistual Basic.Net เพิ่มเติม
           เพื่อนำมาปรับใช้ในการเขียนโปรแกรม
           จะทำให้ท่านสามารถสร้างโปรแกรมจากภาษา Lua เป็นผลสำเร็จ.





 

Coolfirmed by (0)สมาชิก:
 
« แก้ไขครั้งสุดท้าย: 09 ธันวาคม 2011, 12:08:08 โดย sak2005 »
จำเป็นต้องใช้ FlashPlayer

คำคม: เมื่อเวลาเปลี่ยน.. ทุกอย่างเปลี่ยน..