+ 1

I would like some help getting all code turned into C code.

{{LSL_Function |sort=Frand |func=llFrand |func_id=8 |func_sleep=0.0 |func_energy=10.0 |p1_type=float |p1_name=mag |p1_desc=Any valid float value |return_type=float |return_text=that is pseudo random number in the range [0.0,mag) or (mag, 0.0]. |spec=returns a pseudo random number in range [0.0, mag) or (mag, 0.0], depending upon the sign of mag. |caveats |examples=<lsl>default { touch_start(integer total_number) { // When touched, say "Heads" with probability 0.5, // otherwise, say "Tails." if ( llFrand(1.) < .5) llSay(0, "Heads"); else llSay(0, "Tails"); } }</lsl> |func_helpers |also |notes= The random number generator is not a source of entropy. The sequence of random numbers are shared across the entire process, and not independently seeded. Therefore, the pseudo random number generation is not suitable for any application which requires completely predictable or completely unpredictable results. |cat1=Math |cat2 |cat3 }}

26th Nov 2018, 6:02 PM
Laura Munger
Laura Munger - avatar
14 Respuestas
+ 6
Seems like a big plate of spaghetti! 8D Anyway! I think the first step to port this "Linden Scripting Language" code to C is answering these questions: 1. Is there any common feature between these two languages or they are from two different planets? For example, the way the variables are defined or mathematical operations get performed. 2. If you failed to answer the first question, then you still have a chance to make it from scratch. How? Well, first, you should know the mechanics of the code. That is, the main problem for which this code has been developed. For example, the main problem says "A random number must be generated in the range of [1 to 6] to simulate a die roll". 3. Now, if you reached to this point, that means you can implement the solution for the problem. But you haven't the required tools! By tools, I mean you need to know C. So the game is about to begin for you and you're in the right place to start off. https://www.sololearn.com/Course/C/ _____ https://en.wikipedia.org/wiki/Second_Life
26th Nov 2018, 7:35 PM
Babak
Babak - avatar
+ 4
/* test various LSL syntax highlighting elements */ default { state_entry() { integer UPPER_CASE = 1+1; // it should not be highlighted as a constant OBJECT_CLICK_ACTION; // newest keyword at the time of writing llTransferLindenDollars("3d6181b0-6a4b-97ef-18d8-722652995cf1", DEBUG_CHANNEL); }   experience_permissions_denied() { while (success) { llExecCharacterCmd(CHARACTER_CMD_JUMP, [1.0]); llSleep(0.5); list MyList = llGetAttachedList(id); } llSetInventoryPermMask("Object", MASK_NEXT, PERM_COPY); llTakeCamera(); llSound(); ATTACH_LPEC; event; state default; } } So what you see now? Which structures can be found and which ones can't be found in C?
26th Nov 2018, 8:17 PM
Babak
Babak - avatar
+ 4
Thanks, Laura for clarifying the structure. So, let's do it one step at a time, okay? The most basic Linden Script default{timer(){}} The most basic C program int main() {} ~~~~~ <globals> contains declarations for variables and functions which are globally accessible, right? So there is a similar concept in C/C++ called the prototype. Prototypes are considered "incomplete" because they have no definition (body) yet. To make it complete, the definition part goes after the main function. For example, you would declare some functions before main and their definition after the main like so // ** Declarations ** int generateRandom(int lower, int upper); void sortList(int *list); int main() { } // ** Definitions ** int generateRandom(int lower, int upper) { // internal mechanics to produce a random number } void sortList(int *list) { // internal mechanics to sort a list of numbers } ~~~~~~~ <other_states> hasn't any similarity with C's structures because you are able to define as many functions/variables as you want like above. So, roughly speaking, you can port some of them with minor changes without any problem, but as you can see, there are functions which are part of the language itself like `llTakeCamera()` and `llSound()`, and there's no way to implement them in C.
26th Nov 2018, 9:24 PM
Babak
Babak - avatar
+ 4
I'm glad to hear that you have such achievable goal in mind. Even though it requires you to know Java more than C and the facilities that Android SDK provided for developers which are awesome in terms of flexibility, but your main challenge is probably getting deeper into the Linden Scripting Language and collecting the details of the language to have a big picture for your design.
26th Nov 2018, 9:49 PM
Babak
Babak - avatar
+ 3
So, tell me, why are you trying to port it to C?
26th Nov 2018, 9:35 PM
Babak
Babak - avatar
+ 3
Excellent. that's where you find the language documentation and all you need to know to get yourself ready for the next step. The tutorial item [http://wiki.secondlife.com/wiki/LSL_Tutorial] + The `LSL Language Reference` pane covers the language basics which are an important part to start off with. Once you feel that you are ready to go further and see the world from 50000 ft, you'd go here [http://wiki.secondlife.com/wiki/Get_source_and_compile] and see what you need to build a viewer for your target platform. More importantly, don't forget to register on the Second Life forum. _____ https://community.secondlife.com/forums/topic/43144-how-to-create-a-sl-viewer/ https://community.secondlife.com/forums/forum/227-viewers/
27th Nov 2018, 6:24 AM
Babak
Babak - avatar
+ 2
A script must adhere to the following structure: <globals> <default_state> <other_states> <globals> are zero or more global declarations. Each global declaration is either a variable declaration or a user-defined function declaration. <default_state> is a state. It is declared with the keyword defaultfollowed by an open brace symbol {, then one or more event declarations, and finally a close brace symbol }. This state is mandatory. <other_states> are zero or more states. If you need more states than default, you can define them with the keyword state followed by the state name, then an open brace symbol {, then one or more event declarations, and finally a close brace symbol }. See state for more information. The shortest script that can be written is: default{timer(){}} which has a default state containing a timer event, which will do nothing because the script lacks the code necessary to trigger it. So, this script does nothing at all. Spaces and newlines between words or symbols can be used at will
26th Nov 2018, 8:26 PM
Laura Munger
Laura Munger - avatar
+ 2
Yes there are lots of similarities found it out about two weeks ago. LSL Coding is supposedly a cross between C and Python. From the info I collected of the internet and the lsl wiki pages
26th Nov 2018, 9:32 PM
Laura Munger
Laura Munger - avatar
+ 2
Maybe make a platform for it like a app for Android maybe. I know now one have ever made one for just learning it or practicing it for any kind of phone or tablet.
26th Nov 2018, 9:38 PM
Laura Munger
Laura Munger - avatar
+ 2
Well that is if I can figure out how to do that.
26th Nov 2018, 9:40 PM
Laura Munger
Laura Munger - avatar
27th Nov 2018, 2:46 AM
Laura Munger
Laura Munger - avatar
+ 2
This is where I've gotten most of my information about coding for LSL
27th Nov 2018, 2:53 AM
Laura Munger
Laura Munger - avatar
+ 1
/* test various LSL syntax highlighting elements */ default { state_entry() { integer UPPER_CASE = 1+1; // it should not be highlighted as a constant OBJECT_CLICK_ACTION; // newest keyword at the time of writing llTransferLindenDollars("3d6181b0-6a4b-97ef-18d8-722652995cf1", DEBUG_CHANNEL); }   experience_permissions_denied() { while (success) { llExecCharacterCmd(CHARACTER_CMD_JUMP, [1.0]); llSleep(0.5); list MyList = llGetAttachedList(id); } llSetInventoryPermMask("Object", MASK_NEXT, PERM_COPY); llTakeCamera(); llSound(); ATTACH_LPEC; event; state default; } }
26th Nov 2018, 7:54 PM
Laura Munger
Laura Munger - avatar
+ 1
part of LSL grammarhexadecimalRGB DecimalRGB Percentagedefault text#0000, 0, 00, 0, 0comments#cd4d26205, 77, 380.804, 0.302, 0.149states#801a4d128, 26, 770.502, 0.102, 0.302events#004d800, 77, 1280, 0.302, 0.502functions#820124130, 1, 360.510, 0.004, 0.141integer constants#1a1a8026, 26, 1280.102, 0.102, 0.502string constants#1a4d8026, 77, 1280.102, 0.302, 0.502float constants#4d1a8077, 26, 1280.302, 0.102, 0.502vector & rotation constants#636102, 51, 1020.400, 0.200, 0.400operators#0000, 0, 00, 0, 0storage type#1a4d1a26, 77, 260.102, 0.302, 0.102strings#0300, 51, 00, 0.200, 0numbers#f00255, 0, 01, 0, 0keywords#0000cd0, 0, 2050, 0, 0.804
27th Nov 2018, 5:05 PM
Laura Munger
Laura Munger - avatar