Welcome to the Builder Academy

Question Trigger Of The Day (Advanced) - Calculator

More
16 Jul 2012 12:28 #382 by Fizban
An old scripted calculator I wrote several years ago. Fairly complex and admittedly not directly useful at all, but it does contain some fairly infrequently used functions most people that use trigedit may not be familiar with (extract, strlen, charat, etc.).
Code:
Name: 'Calculator', VNum: [57742], RNum: [ 4235] Trigger Intended Assignment: Rooms Trigger Type: Command , Numeric Arg: 7, Arg list: * Commands: if %cmd% == math if %arg.cdr% extract number1 1 %arg% extract operation 2 %arg% extract number2 3 %arg% if %operation% == ^ set lengthofnum2 %number2.strlen% set lastnum %number2.charat(%lengthofnum2%)% if %number2% > 10 && %number2% < 20 set suffix th else switch %lastnum% case 1 set suffix st break case 2 set suffix nd break case 3 set suffix rd break default set suffix th break done end set formula %number1% raised to the %number2%%suffix% power if %number2% == 1 set outcome %number1% elseif %number2% == 0 set outcome 1 else eval i %number2% if %i% > 101 %echo% That would loop more than 100 times, aborting. halt end eval temp_answer %number1% while %i% > 1 eval temp_answer2 %temp_answer% * %number1% eval temp_answer %temp_answer2% set outcome %temp_answer% eval i %i% - 1 done end %echo% The answer to %formula% is: %outcome%. elseif %operation% == + eval ans 4 %operation% 2 if %ans% == 6 eval sum %number1% + %number2% %echo% The sum of %arg% is %sum%. elseif %ans% == 2 eval difference %number1% - %number2% %echo% The difference of %arg% is %difference%. end elseif %operation% == divided_by eval quotient %number1% / %number2% if %number1% > %quotient% * %number2% eval remdiff %quotient% * %number2% eval rem %number1% - %remdiff% %echo% The quotient of %arg% is %quotient% %rem%/%number2%. else %echo% The quotient of %arg% is %quotient% end elseif %operation% == x eval product %number1% * %number2% %echo% The product of %arg% is %product% else %echo% For this to work you must type math followed by 2 integers seperated by an operation. %echo% For example: math 5 \^ 4 OR math 4 + 2 end else %echo% For this to work you must type math followed by 2 integers seperated by an operation. %echo% For example: math 5 \^ 4 OR math 4 + 2 end else return 0 end

Please Log in or Create an account to join the conversation.

Time to create page: 0.164 seconds