海归网首页   海归宣言   导航   博客   广告位价格  
海归论坛首页 会员列表 
收 藏 夹 
论坛帮助 
登录 | 登录并检查站内短信 | 个人设置 论坛首页 |  排行榜  |  在线私聊 |  专题 | 版规 | 搜索  | RSS  | 注册 | 活动日历
主题: [原创[分享][深夜无眠Secondlife对象编程语言LSL汉化] 第四章中英文 --
回复主题   printer-friendly view    海归论坛首页 -> 海归商务 -> 项目找投资与合作           焦点讨论 | 精华区 | 嘉宾沙龙 | 白领丽人沙龙
  阅读上一个主题 :: 阅读下一个主题
作者 [原创[分享][深夜无眠Secondlife对象编程语言LSL汉化] 第四章中英文 --   
文清
[博客]
[个人文集]





头衔: 海归上尉

年龄: 42
加入时间: 2006/12/21
文章: 883

海归分: 8578





文章标题: [原创[分享][深夜无眠Secondlife对象编程语言LSL汉化] 第四章中英文 -- (1649 reads)      时间: 2007-1-21 周日, 09:32   

作者:文清项目找投资与合作 发贴, 来自【海归网】 http://www.haiguinet.com

Chapter 4. Flow Control 流控制
LSL comes with a complete complement of constructs meant to deal with conditional processing, looping, as well as simply jumping to a different point in the sc<x>ript. LSL在程序中,可以条件处理,环,以及直接跳到另一个点.
________________________________________
4.1. Conditional Statements 条件语句
The 'if' statement operates and has the same syntax as the Java/C version.
If条件语句和Java/C语句语法意思一样.这个不翻译了.找本C 基础看.
check_message(string message)
{
if(message == "open")
{
open();
}
else if(message == "close")
{
close();
}
else
{
llSay(0, "Unknown command: " + message);
}
}

The statements between the open and close curly brace are performed if the conditional inside the parentheses evaluates to a non-zero integer. Once a conditional is determined to be true (non-zero), no further processing of 'else' conditionals will be considered. The NULL_KEYconstant is counted as FALSE by conditional ex<x>pressions.
There can be zero or more 'else if' statements, and an optional final 'else' to handle the case when none of the if statements evaluate to a non-zero integer.
The usual set of integer arithmetic and comparison operators are available.
// a function that accepts some information about its environment and
// determines the 'best' next step. This kind of code might be
// part of a simple box meant to move close to an agent and attach to
// them once near. This code sample relies on the standard linden
// library functions as well as two other methods not defined here.
assess_next_step(integer perm, integer attached, integer balance, float dist)
{
string msg;
if(!attached)
{
if((perm & PERMISSION_ATTACH) && (dist <10> 10.0) || ((dist > 20.0) && (balance > 1000)))
{
move_closer();
}
else
{
llRequestPermissions(llGetOwner(), PERMISSION_ATTACH);
}
}
}

________________________________________
4.2. Loop Constructs 这个和C 完全相同,不翻译了.
Loops are a basic building block of most useful programming languages, and LSL offers the same loop constructs as found in Java or C.
________________________________________
4.2.1. for loop
A for loop is most useful for when you know how many times you need to iterate over an operation. Just like a Java or C for loop, the parentheses have three parts, the initializer, the continuation condition, and the increment. The loop continues while the middle term evaluates to true, and the increment step is performed at the end of every loop.
// move a non-physical block smoothly upward (positive z) the total
// distance specified divided into steps discrete moves.
move_up(float distance, integer steps)
{
float step_distance = distance / (float)steps;
vector offset = <0>;
vector ba<x>se_pos = llGetPos();
integer i;
for(i = 0; i <steps> 10.0)
{
jump early_exit;
}

// make sure we're roughly pointed toward the target.
// the calculation of max_cos_theta could be precomputed
// as a constant, but is manually computed here to
// illustrate the math.
float max_cos_theta = llCos(PI / 4.0);
vector toward_target = llVecNorm(target_pos - pos);
rotation rot = llGetRot();
vector fwd = llRot2Fwd(rot);
float cos_theta = toward_target * fwd;
if(cos_theta > max_cos_theta)
{
jump early_exit;
}

// at this point, we've done all the checks.
attach();

@early_exit;
}

________________________________________
4.4. State Change 状态改变 (此处恐龙不是很懂,需要进行程序调试几次实验后才可以明白.)
State change allow you to move through the lsl virtual machine's flexible state machine by transitioning your sc<x>ript to and from user defined states and the default state. You can define your own sc<x>ript state by placing the keyword 'state' before its name and enclosing the event handlers with open and close curly braces ('{' and '}'.) You can invoke the transition to a new state by calling it with the syntax: 'state <statename>'.
状态改变允许你在LSL虚拟机中保持可变状态,把指令在定义状态和默认状态间切换.把'state'这个词,放在程序段前,然后用('{' and '}'.)符号把事件指针括起来.然后通过语法: 'state <statename>'赋予一种新的状态来进行调用.
default
{
state_entry()
{
llSay(0, "I am in the default state");
llSetTimer(1.0);
}
//下面4行就是 'state',放程序段前,用('{' and '}'.)符号把事件指针括起来
timer()
{
state SpinState;
}
}
//例: 通过语法: 'state <statename>'赋予一种新的状态来进行调用.
state SpinState
{
state_entry()
{
llSay(0, "I am in SpinState!");
llTargetOmega(<0>, 4, 1.0);
llSetTimer(2.0);
}

timer()
{
state default;
}

state_exit()
{
llTargetOmega(<0>, 0, 0.0);
}
}



作者:文清项目找投资与合作 发贴, 来自【海归网】 http://www.haiguinet.com









相关主题
[原创[分享][深夜无眠Secondlife对象编程语言LSL汉化] 第三... 创业论坛 2007-1-21 周日, 09:33
[原创[分享][深夜无眠Secondlife对象编程语言LSL汉化] 说明 创业论坛 2007-1-21 周日, 09:45
[原创[分享][深夜无眠Secondlife对象编程语言LSL汉化] 目... 创业论坛 2007-1-21 周日, 09:35
[原创[分享][深夜无眠Secondlife对象编程语言LSL汉化] 第... 创业论坛 2007-1-21 周日, 09:31
[原创[分享][深夜无眠Secondlife对象编程语言LSL汉化] 第... 创业论坛 2007-1-21 周日, 09:26
[原创[分享][深夜无眠Secondlife对象编程语言LSL汉化] 第... 创业论坛 2007-1-21 周日, 09:23
[分享]另一篇关于中国问题的文章,英文版 海归主坛 2009-7-12 周日, 15:07
谁用过Fortran?著名编程语言Fortran创始人巴库斯辞世 海归茶馆 2007-3-20 周二, 18:14

返回顶端
阅读会员资料 文清离线  发送站内短信
  • [原创[分享][深夜无眠Secondlife对象编程语言LSL汉化] 第四章中英文 -- -- 文清 - (5072 Byte) 2007-1-21 周日, 09:32 (1649 reads)
显示文章:     
回复主题   printer-friendly view    海归论坛首页 -> 海归商务 -> 项目找投资与合作           焦点讨论 | 精华区 | 嘉宾沙龙 | 白领丽人沙龙 所有的时间均为 北京时间


 
论坛转跳:   
不能在本论坛发表新主题, 不能回复主题, 不能编辑自己的文章, 不能删除自己的文章, 不能发表投票, 您 不可以 发表活动帖子在本论坛, 不能添加附件可以下载文件, 
   热门标签 更多...
   论坛精华荟萃 更多...
   博客热门文章 更多...


海归网二次开发,based on phpbb
Copyright © 2005-2026 Haiguinet.com. All rights reserved.