中国虚拟军事网(VME)- 专注于武装突袭系列虚拟军事游戏

 找回密码
 加入VME

QQ登录

只需一步,快速开始

搜索
查看: 1237|回复: 2

关于惰性求值的一些使用例子

[复制链接]
发表于 2015-10-3 17:44:00 | 显示全部楼层 |阅读模式
本帖最后由 啤酒冲米二 于 2015-10-3 18:37 编辑

版主的脚本编写高级教程有惰性求值的讲解

以下例子可以举一反三,对于一个语句中有很多判断有很好的优化效果

惰性求值:
布尔 [and/or] 代码 [and/or] 代码 … [and/or] 代码
布尔 [and/or] 代码 [and/or] 代码(运算符不同时代码即大括号里面又可以是布尔 [and/or] 代码...)  [and/or] 代码
第一个必须是布尔!

call _a 相当于布尔
_a相当于代码

_a={hint"0";true};_b={hint"1";false};_c={hint"2";false};_d={hint "3";true};_e={hint "4";false};   
if (call _a or _b or {call _c && _d} or _e) then{};  //_a处退出 显示“0”

_a={hint"0";false};_b={hint"1";false};_c={hint"2";true};_d={hint "3";true};_e={hint "4";false};   
if (call _a or _b or {call _c && _d} or _e) then{};  //_d处退出 显示“3”

_a={hint"0";false};_b={hint"1";false};_c={hint"2";false};_d={hint "3";true};_e={hint "4";false};   
if (call _a or _b or {call _c && _d} or _e) then{};  //_d不执行 _e处退出 显示“4”


_a={hint"0";false};_b={hint"1";true};_c={hint"2";true};_d={hint "3";true};  
if (call _a && _b && (call _c || _d)) then{};  //_b,_d不执行 _c处退出 显示“2”  有计算浪费

_a={hint"0";false};_b={hint"1";true};_c={hint"2";true};_d={hint "3";true};  
if (call _a && _b && {call _c || _d}) then{};  //_a处退出 显示“0”






发表于 2016-3-16 13:39:58 | 显示全部楼层
不错,顶一下
发表于 2016-3-17 22:28:39 | 显示全部楼层
完全迷茫了。。。嘎嘎,凑字。。
您需要登录后才可以回帖 登录 | 加入VME

本版积分规则

小黑屋|中国虚拟军事网

GMT+8, 2024-3-29 23:08

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表