Author Topic: New to scripting  (Read 4520 times)

0 Members and 1 Guest are viewing this topic.

Offline Jasper8282Topic starter

  • Newbie
  • *
  • Posts: 3
  • Activity:
    0%
  • Reputation Power: 0
  • Jasper8282 has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
New to scripting
« on: December 12, 2012, 05:57:45 PM »
0
I was wondering if anyone had any good documentation on writing out new scripts.  I have a programming/coding background, but I have never seen this syntax before... I think it might be LUA?  I did some looking around, but I have a feeling I didn't look hard enough.  I would love some links that could help me get started.  I want to create so many scripts with great UI's.  I think the UI is one of the most important features of coding because if it is too confusing to use... then people will generally look elsewhere for something similar.

Offline KaliOfLS

  • That's "Dr." Kali to you!
  • Sr. Member
  • *
  • Posts: 406
  • Activity:
    0%
  • Reputation Power: 6
  • KaliOfLS has no influence.
  • Gender: Male
  • Respect: +33
  • Referrals: 2
    • View Profile
Re: New to scripting
« Reply #1 on: December 12, 2012, 06:35:41 PM »
0
http://www.lua.org/docs.html

For specifics to oEUO:

http://www.easyuo.com/openeuo/wiki/index.php/Main_Page

GUI are done with Delphi.  TObjects basically, and it's hard to find documentation for it because it is a bastardized version in oEUO than the full Delphi object set.  It was designed to be enough for scripts.  However- the objects.dll file that Cheffe has provided has some bugs in it, so right now, they aren't completely stable.

http://www.easyuo.com/forum/viewtopic.php?f=37&t=49071

You should check out that link.. lot of good information in it for menus.


----
What is your background language?
I programmed in C++ and found lua to be a nice comparison, relative to euox scripting.
functions instead of subs, local variables (except in lua we have upvalues that would not be allowed in C++), metatables- remind me of structs, but with some work to the index you can sort of turn them into an OO class.  There are no vectors, but there are dynamically allocated tables.  Even more interesting is that you can have all sorts of keys.

[snippet]
local t = { [1] = 'One', [2] = 'Two', [3] = 'Trees', ['Potato'] = 'Vegetable'}
[/snippet]

Granted, it makes it more annoying to iterate the table :p  
R~~~~ B~~~~~~~~ 
^ real life signature for sure

Offline KaliOfLS

  • That's "Dr." Kali to you!
  • Sr. Member
  • *
  • Posts: 406
  • Activity:
    0%
  • Reputation Power: 6
  • KaliOfLS has no influence.
  • Gender: Male
  • Respect: +33
  • Referrals: 2
    • View Profile
Re: New to scripting
« Reply #2 on: December 12, 2012, 08:02:10 PM »
0
I was going to add this but had to run for a few minutes.  I'll finish up with some simple tutorials
Since you've also had previous experience, I'll be brief with the concepts, and you can take it from there.
Code: [Select]
--Comments

--global and local variables.  _G is the global namespace, and you can change that if you want. local is a subset of _G and you can have different local environments in _G

function what()
   print(i)
   return
end

i = 10
local i = 5

what()  --prints 10 because first the function looks for a locally defined i, when there isn't one it moves on to the global environment.

--For future reference, when ever i make a comment like --====================--  assume it's a new script thread
--========================--

function what()
   local i = 7
   print(i)
end

i = 10
local i = 5

what() --prints 7 !?!?!  because it finds a local i, it never looks into the global namespace

--=======================--
--  Let the fun begin

i = 10
local i = 5

function what()
   print(i)
   return
end

what()   -- Prints 5!?  No local i in the block, but any inner scope block will check the containing blocks local namespace for a variable identifier

--=======================
local i = 5

function what()
    print(i)
    return
end

i = 7

what() --prints 7 because I've defined a local i before the inner block function, and changed the value of that local value before calling the function.
--========================--
--===We'll come back to this====--
-----------------------------------
--Another way to define functions is as an 'anonymous' function

local i = 2

local var = function()
               print(i)
               return
   end

var()  --prints 2 as we expected.

--===========================--
-- Where am I going with this?
-- neat runtime function defintion, not something we typically do in C++

for i = 1, 5 do
   local var = function()  print(i) return end
   var()
end

--==========================--
-- Continuing to build on this:
for i = 1, 5 do
   local var = function()  print(i) return end
   var()
end

var() --no global or local value var() defined because we defined it in an inner block scope.  
--==========================
--  If you're familiar with scope, we are completely on track here of what we expect.
--  Okay, we're finally getting to the lesson that I learned while making buttons in a looping method
--  And a huge part of lua that took me a long time to understand, bear with my boring examples


local var ;defintion
local j = 2
if true then
   local i = 5
   var = function() print(i*j) return end
end
print(i)   --Prints nil because the only defined i we have is a local i within the if block.
var()     --Prints 10!   How?? We already established at this point, the local i variable doesn't exists!  This is called an 'upvalue'

--======================================--
local var = {}
for i = 1, 5 do
   var[i] = function() print(i) return end  ;you can set table values to functions
end

var[2]() ;at the definition time, i was 2, so this prints 2.
--======================================--
-- time to mind fk you
local var = {}
local i = 1
while i <= 5 do
   var[i] = function() print(i) return end
   i = i + 1
end

var[2]() --Prints 6.  Want to know why??
--because the variable i never left the current variable scope!!  So even during the defintion, the i was 2, when we called the function,
--lua looked for a local i, and it searched a block up and found a local i, which left the while loop at 6.  S
--======================================
--What if we didn't want that behavior?
local var = {}
local i = 1
while i <= 5 do
   local j = i
   var[i] = function() print(j) return end
   i = i + 1
end

var[2]()  --prints 2 again :)


Okay, that's my variable scope lesson.  





 
« Last Edit: December 12, 2012, 08:12:57 PM by KaliOfLS »
R~~~~ B~~~~~~~~ 
^ real life signature for sure

Offline KaliOfLS

  • That's "Dr." Kali to you!
  • Sr. Member
  • *
  • Posts: 406
  • Activity:
    0%
  • Reputation Power: 6
  • KaliOfLS has no influence.
  • Gender: Male
  • Respect: +33
  • Referrals: 2
    • View Profile
Re: New to scripting
« Reply #3 on: December 12, 2012, 08:46:45 PM »
0
lua is not a strict type language but supported 'types' would be doubles(floats? i do not remember my programming enough to remember the max values of doubles vs. floats nor do I know the max lua number), int, strings (obviously char because string is C* right), booleans, tables, and nil (null if your a c programmer)

I am not going to teach you everything here because it would be a glorious waste of my time and others who have already written these tuts, my aim is to get your feet on the ground so you can start running on learning the scripting language wherever your script ideas take you.

Code: [Select]
local num = 4
print(num) --4
print(type(num)) -- 'number'
num = num / 5  --+,-,/,*,% are acceptable operators for numbers 
print(num) -- 0.8
print(type(num)) -- 'number'
num = 'It does not care you just made it a string'
print(num)
print(type(num)) -- 'string'
num = "a"
print(type(num)) -- 'string'
num = true
if num then print(num) end --prints (true)
local s = 'This statement will produce an error '
if not num then print(s..num) end   --concat is ..  but you can not concat strings with numbers/booleans
if num then print(s..tostring(not num)) end --you can tostring numbers and booleans, not tables.  Well, you can but it spits out the table address
--Alright, enough with variable types.  Lets push the ticket.
--===========================================--
--Tables!
--Inserting values
local t = {}   -- { } denotes table.
t[1] = 2
t[2] = 4
for i = 3, 10 do
   t[i] = 2*i
end
--First, I'll teach about the # operator.
print(#t)  --prints 10, because there are 10 elements in t.
for i = 1, #t do print(t[i]) end -- prints 2,4,..20
--now, the in ipairs function
for k,v in ipairs(t) do
   print('t['..tostring(k)..'] = '..tostring(v)..', ')
end
--now the in pairs function
for k,v in pairs(t) do
  print(tostring(k)..' '..tostring(v))  --same as ipairs in this case
end
--now the caveats
t = {}
t = { ['Hello'] = 'Good Bye', ['Hallo'] = 'Chuse' }
print(#t) --prints 0 because you aren't using a contiguous integer key set.  Thus:
for i = 1, #t do
   print(t['Hello'])  --never enters because the for loop is for i = 1, 0. 
end
--the for k,v in ipairs(t) also fails because it ipairs is an ordered pair call and you do not have an ordered pair of keys and values.
--BUT the following works :)
for k,v in pairs(t) do
   print(k..' '..v)
end
--The caveat, is the printed pair follows no specific order.
t = {}
for i = 1, 5 do
   t[i] = i
end
--let us say we want to introduce a new element to the table at key 3, but we don't want to over right that value, but push it back.
-- the long way is
for i = #t, 3 do
   t[i+1] = t[i]
end
t[3] = 'New Value'
-- The short way
table.insert(t,3,'New Value')
--Done.

Okay, I'm done for now.  Play around, ask questions.


R~~~~ B~~~~~~~~ 
^ real life signature for sure

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13304
  • Activity:
    0.6%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: New to scripting
« Reply #4 on: December 12, 2012, 09:44:47 PM »
0
One of my favorite programming books is Programming in Lua  There really aren't many books for Lua, but with this one who needs any more?
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline KaliOfLS

  • That's "Dr." Kali to you!
  • Sr. Member
  • *
  • Posts: 406
  • Activity:
    0%
  • Reputation Power: 6
  • KaliOfLS has no influence.
  • Gender: Male
  • Respect: +33
  • Referrals: 2
    • View Profile
Re: New to scripting
« Reply #5 on: December 12, 2012, 09:50:47 PM »
0
One of my favorite programming books is Programming in Lua  There really aren't many books for Lua, but with this one who needs any more?

I gave him the parent link to that, but I second this one.  I have used this numerous times, but unfortunately, I read it, I don't really get it, I try some things, get frustrated, ximan mushroom stamps me with a link and example, to this book again, and I reread it, and I understand. 

Agreed.  This is the best.  I just tried to get him going on his path to experimentation.  That's how I learn, trial and error.. maybe not the most efficient, but I learn it for good. 
R~~~~ B~~~~~~~~ 
^ real life signature for sure

Offline Crome969

  • Elite
  • *
  • *
  • Posts: 2098
  • Activity:
    0%
  • Reputation Power: 25
  • Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.
  • Gender: Male
  • UO Enthusiast
  • Respect: +211
  • Referrals: 10
    • View Profile
    • ScriptSDK
Re: New to scripting
« Reply #6 on: December 13, 2012, 01:27:43 AM »
0

Offline KaliOfLS

  • That's "Dr." Kali to you!
  • Sr. Member
  • *
  • Posts: 406
  • Activity:
    0%
  • Reputation Power: 6
  • KaliOfLS has no influence.
  • Gender: Male
  • Respect: +33
  • Referrals: 2
    • View Profile
Re: New to scripting
« Reply #7 on: December 13, 2012, 06:30:52 AM »
0
I think Raba released a .net wrapper for the UO.dll file already.
https://www.easyuo.com/forum/viewtopic.php?f=37&t=48950&hilit=.net+wrapper

The current available release is 0.3:
RabaEUOdotNET 0.3 source: http://bit.ly/Sjo3q7
RabaEUOdotNET 0.3 dll precompiled binary: http://bit.ly/TVWRv5
RabaEUOforVBNET 0.3 source: http://bit.ly/SvrdFi

Also if you're interested.
R~~~~ B~~~~~~~~ 
^ real life signature for sure

Offline Jasper8282Topic starter

  • Newbie
  • *
  • Posts: 3
  • Activity:
    0%
  • Reputation Power: 0
  • Jasper8282 has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
Re: New to scripting
« Reply #8 on: December 13, 2012, 08:05:44 AM »
0
Thank you for all of the links and information.  I do know a good amount of C++.  I almost know Java, Javascript, Perl, VB, and some HTML and database languages like SQL and PL/SQL.  I was taught C++ first and most of everything became much easier after that because it was somewhat similar... except for Perl.  I will definitely look over all of the links when I get home from work today.  Also thank you for the information on GUI's for the scripts.

Hopefully within a couple weeks I will have a few scripts to test out that I've written.

Offline Crome969

  • Elite
  • *
  • *
  • Posts: 2098
  • Activity:
    0%
  • Reputation Power: 25
  • Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.
  • Gender: Male
  • UO Enthusiast
  • Respect: +211
  • Referrals: 10
    • View Profile
    • ScriptSDK
Re: New to scripting
« Reply #9 on: December 13, 2012, 08:09:32 AM »
0
I think Raba released a .net wrapper for the UO.dll file already.
https://www.easyuo.com/forum/viewtopic.php?f=37&t=48950&hilit=.net+wrapper

The current available release is 0.3:
RabaEUOdotNET 0.3 source: http://bit.ly/Sjo3q7
RabaEUOdotNET 0.3 dll precompiled binary: http://bit.ly/TVWRv5
RabaEUOforVBNET 0.3 source: http://bit.ly/SvrdFi

Also if you're interested.
But the problem remains on euo \oeuo : its memory based. As long as its updated you guys will be happy , if cheffe stop you will be all stucking:)

Offline KaliOfLS

  • That's "Dr." Kali to you!
  • Sr. Member
  • *
  • Posts: 406
  • Activity:
    0%
  • Reputation Power: 6
  • KaliOfLS has no influence.
  • Gender: Male
  • Respect: +33
  • Referrals: 2
    • View Profile
Re: New to scripting
« Reply #10 on: December 13, 2012, 08:17:06 AM »
0
I think Raba released a .net wrapper for the UO.dll file already.
https://www.easyuo.com/forum/viewtopic.php?f=37&t=48950&hilit=.net+wrapper

The current available release is 0.3:
RabaEUOdotNET 0.3 source: http://bit.ly/Sjo3q7
RabaEUOdotNET 0.3 dll precompiled binary: http://bit.ly/TVWRv5
RabaEUOforVBNET 0.3 source: http://bit.ly/SvrdFi

Also if you're interested.
But the problem remains on euo \oeuo : its memory based. As long as its updated you guys will be happy , if cheffe stop you will be all stucking:)

lol please don't die Cheffe (or stop updating oEUO).. I'm quite certain that I might quit playing UO if I couldn't script.
So stealth is packing sniffing and injecting packets into the data stream?  Wouldn't that also be dependent upon encryption and data packet organization?  Doesn't that change with updates?  I don't know, so I'm asking :)
R~~~~ B~~~~~~~~ 
^ real life signature for sure

Tags: