Entraides et échanges autour de la technologie Scol - Informations and exchanges on the Scol technology
Vous pouvez changer la langue de l'interface une fois inscrit - You can change the language once registered
You are not logged in.
In my quest for making an avatar script, I figured I should start with doing the following:
1. creating a custom object (in this case, a simple one, a circle whose only properties are a name (string) and diameter (integer to make it easy).
2. creating a list of custom objects
3. searching for the diameter of an object in the list by searching for its name using the [first next[ method
4. changing the diameter of an object by searching for its name using the [first next[ recursive method and then changing the diameter
5. removing a circle from the list of circles (not sure of what method to use, hopefully I will do it without having to use os3d (although doing this with os3d is my goal)
6. adding a circle to the list of circles
7. finding the index of a specific circle by name using the [first next] recursive method.
The goal is to create a list of avatar objects (which will be created using the login information of each user and other messages from the chat server), changing their positions, interpolating movement from one place to another, and eventually adding a 'health' property for a fps or fce (first creature eat) game.
Here is my pseudo code filled with syntax errors I am sure. I will be using a ObjRichText to display text but this pseudo code uses the console. I haven't tried this out yet but wrote it down on paper yesterday. This code attempts to put into practice steps 1, 2, and 3.
//pseudo code
// create a custom circle object. it's simple, just with a name and diameter
struct Circle = [nameCircle S, diamCircle: I]mkCircle;;
//creature a counter to let me know at which element I am at in the list of circles
var listcounter=1;;
//make some circles!!!! each named after a megalomaniac
var Circle1=mkCircle["Alexander the Great" 3];;
var Circle2=mkCircle["The Great Khan" 8];;
var Circle3=mkCircle["Napoleon Bonaparte" 7];;
//create the type of list that will hold circles
typeof Circlelist = [[Circle]r1];;
//fill the Circlelist with Circles
var Circlelist = Circle1::Circle2::Circle3::nil;;
//loop through list looking for the diameter of the Circle named "Alexander the Great"
fun find_diameter_of_circle_by_name(Circlelist)=
if
//open if brace
(
Circlelist==nil then
//we are at the end of the so now we can show how many elements are in it
_fooS strctn "There are":: itoa counter:: "Cirlcles in the List"
0;
else let Circlelist->[first next] in
//open let brace
(
if first.nameCircle== "Alexander the Great" then
//open if brace
(
//show how many elements are in the complete list
_fooS strctn "The Circle named Alexander the Great has diameter of"::itoa first.diamCircle:: "and its index in the list is":: itoa counter;
//increase counter to reflect index in list
set counter=counter=1;
//close if brace
)
//increase counter to reflect index in list
set counter=counter=1;
//remove first item from Circlelist
set Circlelist= next;
//close let brace
)
//close if brace
)
//end function
0;;
Fellow practicing scol programmers: I've forgotten alot of syntax and will edit as I look over my older work, but feel free to show correct syntax since you are not as rusty as me.
Offline
Hello !
actually in your case you should better use the NetUser struct to identify a user.
also a login can be changed the only persistent user info is the user ID user.NU_id
http://redmine.scolring.org/projects/op … _user.html
the OS3D network API already everything needed to get the login or other user parameter.
http://redmine.scolring.org/projects/op … a_p_i.html
in that way imagine a user list like that
typeof avatarList = [[I StrAvatar] r1]; // I for user.NU_id, StrAvatar the avatar structure with additional variables
//to get an avatar structure by the avatar id
fun getAvatar(id)=
switch avatarList id;; // return the StrAvatar in the list corresponding to the id
//add an avatar in the list
fun addAvatar(id, avatarstr)=
set avatarList = [id avatarstr]::avatarList;;
// remove an avatar from the list see http://redmine.scolring.org/projects/openspace3d/embedded/group__toolslist.html#ga7b45e16579a53a03719c1870a7fdcd17
fun removeAvatarById(id)=
set avatarList = remove_idx_from_list avatarList id;;
or with the user struct
typeof avatarList = [[NetUser StrAvatar] r1]; // NetUser for user structure, StrAvatar the avatar structure with additional variables
//to get an avatar structure by the user struct
fun getAvatar(userstr)=
switch avatarList userstr;; // return the StrAvatar in the list corresponding to the id
//add an avatar in the list
fun addAvatar(userstr, avatarstr)=
set avatarList = [userstr avatarstr]::avatarList;;
// remove an avatar from the list see http://redmine.scolring.org/projects/openspace3d/embedded/group__toolslist.html#ga7b45e16579a53a03719c1870a7fdcd17
fun removeAvatarById(userstr)=
set avatarList = remove_idx_from_list avatarList userstr;;
Offline
Thanks Arkeon...but I better learn how to use structs and lists with something simpler, and my code is dead from almost the start.
And mine is a horse with a broken leg right at the start of the race!
// create a custom circle object. it's simple, just with a name and diameter
struct Circle = [nameCircle: S, diamCircle: I] mkCircle;;
//creature a counter to let me know at which element I am at in the list of circles
typeof listcounter = I;;
var listcounter=1;;
//make some circles!!!! each named after a megalomaniac
typeof Circle1= Circle;;
set Circle1 = mkCircle ["Alexander the Great", 3];
Error:
I can't find my scol voyager log (posted to another thread), but it is something to the effect:
??set Circle1 = mkCircle ["Alexander the Great", 3];
60) unknown set
syntax error
Offline
set Circle1 = mkCircle ["Alexander the Great", 3]; should be in the main function
// create a custom circle object. it's simple, just with a name and diameter
struct Circle = [nameCircle: S, diamCircle: I] mkCircle;;
//creature a counter to let me know at which element I am at in the list of circles
typeof listcounter = I;;
var listcounter=1;;
//make some circles!!!! each named after a megalomaniac
typeof Circle1= Circle;;
fun main()=
set Circle1 = mkCircle ["Alexander the Great", 3];
0;;
Offline
Thanks Arkeon. I'll edit and see how far my horse gets before breaking its leg, a few meters more I would think.
Offline
ok so the same code as before but with the circle struct
// create a custom circle object. it's simple, just with a name and diameter
struct StrCircle = [nameCircle: S, diamCircle: I] mkStrCircle;;
typeof circleList = [[S StrCircle] r1]; // S for name, StrCircle the circle structure with additional variables
//to get an circle structure by the name
fun getCircle(name)=
switchstr circleList name;; // return the StrCircle in the list corresponding to the name
//add a new circle in the list and return the new circlestr
fun addCircle(name, diameter)=
let mkStrCircle [name diameter] -> circlestr in
(
set circleList = [name circlestr]::circleList;
circlestr;
);;
//remove a circle from the list
fun removeCircle(circlestr)=
set circleList = remove_sid_from_list circleList circlestr.nameCircle;;
// remove a circle from the list by its name
fun removeCircleByName(name)=
set circleList = remove_sid_from_list circleList name;;
//get a circle radius
fun getCircleRadius(circlestr)=
circlestr.diamCircle / 2;;
// main function
fun main()=
//add circles
let addCircle "toto" 32 -> circle1 in
let addCircle "thing" 44 -> circle2 in
let addCircle "new thing" 233 -> circle3 in
(
// Do something on the list
_fooI strcat ">>>>>>> thing radius : " (getCircleRadius (getCircle "thing"));
//then remove
removeCircleByName "toto";
removeCircle circle2;
removeCircle circle3;
);
0;;
to use "remove_sid_from_list" add the tool lib in your scol file
_load "tools/os3dlib/tools.pkg"
_load "test/circle.pkg"
main
Last edited by arkeon (29-Nov-2013 17:53:47)
Offline
I figured I would continue to work on the code I have worked on as it's refreshing my memory and I'm not going farther than I can comprehend.
Everything is running now, but the code will not evaluate first.nameCircle to true in any case:
// create a custom circle object. it's simple, just with a name and diameter
struct Circle = [nameCircle: S, diamCircle: I] mkCircle;;
//creature a counter to let me know at which element I am at in the list of circles
typeof listcounter = I;;
//make some circles!!!! each named after a megalomaniac
typeof Circle1= Circle;;
typeof Circle2= Circle;;
typeof Circle3= Circle;;
//create the type of list that will hold circles
typeof Circlelist = [Circle r1];;
//loop through list looking for the diameter of the Circle named "Alexander the Great"
fun find_diameter_of_circle_by_name(list)=
if (list==nil) then
//open if brace
(
//we are at the end of the list so now we can show how many elements are in it
_fooS strcatn "There are" :: " "::(itoa (listcounter-1)) ::" ":: "Cirlcles in the List":: nil;
0;
)
else
//open else brace
(
let list->[first next] in
//open let brace
(
if (first.nameCircle == "Alexander the Great") then
//open if brace
(
//show how many elements are in the complete list
_fooS "hello";
_fooS strcatn "The Circle named Alexander the Great has diameter of"::(itoa first.diamCircle):: "and its index in the list is":: (itoa listcounter)::nil;
//increase counter to reflect index in list
set listcounter=listcounter+1;
//close if brace
find_diameter_of_circle_by_name(next);
0;
)
else
//open else brace
(
//increase counter to reflect index in list
set listcounter=listcounter+1;
//remove first item from Circlelist
_fooS first.nameCircle;
find_diameter_of_circle_by_name(next);
//close else brace
0;
)
//close let brace
);
//close else brace
);
//end function
0;;
fun main()=
_showconsole;
set listcounter= 1;
set Circle1 = mkCircle ["Alexander the Great" 3];
set Circle2=mkCircle ["The Great Khan" 8];
set Circle3=mkCircle ["Napoleon Bonaparte" 7];
set Circlelist = Circle1::Circle2::Circle3::nil;
find_diameter_of_circle_by_name(Circlelist);
0;;
the code that is not evaluating to true is:
if (first.nameCircle == "Alexander the Great") then
Last edited by hebdemnobad (29-Nov-2013 20:30:39)
Offline
However,
if (first.diamCirle == 3)
does evaluate to true...
Offline
Thanks Arkeon...but I better learn how to use structs and lists with something simpler, and my code is dead from almost the start.
And mine is a horse with a broken leg right at the start of the race!
// create a custom circle object. it's simple, just with a name and diameter struct Circle = [nameCircle: S, diamCircle: I] mkCircle;; //creature a counter to let me know at which element I am at in the list of circles typeof listcounter = I;; var listcounter=1;; //make some circles!!!! each named after a megalomaniac typeof Circle1= Circle;; set Circle1 = mkCircle ["Alexander the Great", 3];
Error:
I can't find my scol voyager log (posted to another thread), but it is something to the effect:??set Circle1 = mkCircle ["Alexander the Great", 3];
60) unknown set
syntax error
Scol is a functionnal language, so all are functions.
Variables declarations are also functions, but some special keywords are used (typeof, var, defcomm, struct, proto, etc).
All the rest MUST include in a function, between fun and ;; !
fun functionName (arguments) =
/* any code */
;;
Offline
string compare are not done with == but with
strcmp str1 str2
or
strcmpi str1 str2 (for case insensitive)
if (strcmp first.nameCircle "Alexander the Great") then nil // > 0 the strings are not equal
else // equal
// or
if (!strcmp first.nameCircle "Alexander the Great") then // equal
else // not equal
Offline
//pseudo code // create a custom circle object. it's simple, just with a name and diameter struct Circle = [nameCircle S, diamCircle: I]mkCircle;; //creature a counter to let me know at which element I am at in the list of circles var listcounter=1;; //make some circles!!!! each named after a megalomaniac var Circle1=mkCircle["Alexander the Great" 3];; var Circle2=mkCircle["The Great Khan" 8];; var Circle3=mkCircle["Napoleon Bonaparte" 7];; //create the type of list that will hold circles typeof Circlelist = [[Circle]r1];; //fill the Circlelist with Circles var Circlelist = Circle1::Circle2::Circle3::nil;; //loop through list looking for the diameter of the Circle named "Alexander the Great" fun find_diameter_of_circle_by_name(Circlelist)= if //open if brace ( Circlelist==nil then //we are at the end of the so now we can show how many elements are in it _fooS strctn "There are":: itoa counter:: "Cirlcles in the List" 0; else let Circlelist->[first next] in //open let brace ( if first.nameCircle== "Alexander the Great" then //open if brace ( //show how many elements are in the complete list _fooS strctn "The Circle named Alexander the Great has diameter of"::itoa first.diamCircle:: "and its index in the list is":: itoa counter; //increase counter to reflect index in list set counter=counter=1; //close if brace ) //increase counter to reflect index in list set counter=counter=1; //remove first item from Circlelist set Circlelist= next; //close let brace ) //close if brace ) //end function 0;;
In find_diameter_of_circle_by_name, when Circlelist is nil, counter variable is not declared.
It isn't a good idea using a global variable, use counter as an argument of this function and you increment it to each loop :
find_diameter_of_circle_by_name (lCircle, counter)=
....
Next, Circlelist is your glbal variable AND an argument is this function. Bad idea, change these names !
To increment :
set counter = counter +1;
And few little errors ;-)
Offline
About strcmp / strcmpi :
If the two strings are equal, returns 0
If the first string is before the second (alphabetic order), returns > 0
If the first string is after the second (alphabetic order), returns < 0.
Offline
string compare are not done with == but with
strcmp str1 str2
or
strcmpi str1 str2 (for case insensitive)if (strcmp first.nameCircle "Alexander the Great") then nil // > 0 the strings are not equal else // equal // or if (!strcmp first.nameCircle "Alexander the Great") then // equal else // not equal
Aha Thx I'll make those other changes too Iri.
Offline
I was using JavaScript for a theater project last spring and summer... forgot about where to declare/initialize variables the scol way.
Offline
A good idea to initialize globals : write an init function.
If a reset is needed, a simple call to this init function is sufficient.
Offline
Thx Iri and Arkeon I got my code to work.... I now understand every line of Arkeon's circle code. (I printed it out, got out my reliable pencil, and drew lines between variables to see how he used the assigned the same string to the list element id and circle name. I think I am ready to get to back work on the multi player code using a list of custom avatar objects on the older thread. I've printed up the doxygen documents for the netcomm and netuser objects, so I think I will use the netuser as part of the avatar object as you have so many times suggested. (I had to look through the chat plugit a while to see how things fit together.
I think I will need some help with the prender callback code and movement interpolation.
You guys are so patient and hopeful.
Last edited by hebdemnobad (1-Dec-2013 18:08:00)
Offline
What does the Index refer to in: remove_idx_from_list
is
1. it in the position of a tuple in the list (i.e, the first tuple would be 0, the 100th would be 99)?
or
2. is it the identifier of a tuple of [I u0] where the index is a particular interger regardless of where the tuple is located in the list (so if I am looking for an Index 100, I am not looking for the 101th item in a list, but an item which is a tuple of 100 and some object, regardless of its location in the list
thanks
-h
Offline
This is the answer 2
to get a list element by it's position there is "nth_list"
typeof list = [[I S] r1];;
fun main()=
set list = [1 "hello"]::[24 "world"]::nil;
let nth_list list 0 -> tuple in // return the first element in the list with the full tuple [I S] > [1 "hello"]
let switch list 24 -> p in // return S only from the index 24 found in the first tuple element > "world"
0;;
Offline
thx
Offline
lets say I have a list of tuples of the type
[I Remote_bot}
(remote_bot is the object I am using in the multiplayer script I'm working on now)
and I want to search through a list of such tuples containing interger and remote bots in each tuple in the list
would this be the proper syntax for the function?:
typeof Remote_bot_List = [[I Remote_bot] r1];;
//get a Remote_bot object as return of function where the interger 589 is the first element of the two element tuple of I and Remote_bot
function get_Remote_bot(list, index_to_search)=
switch list index_to_search;;
would this allow me to do the following
//I am looking for the Remote_bot in the Remote_bot_List that == [589 Remote_bot_I_am_looking_for] and I want to alter properties of the Remote_bot_I_am_looking_for
let get_Remote_bot Remote_bot_List 589-> remote_bot_object_I_am_looking_for in
(
//I do what I want to do to the remote_bot_object_I_am_looking_for in the following code
Last edited by hebdemnobad (13-Dec-2013 20:50:22)
Offline
typeof Remote_bot_List = [[I Remote_bot] r1];;
//get a Remote_bot object as return of function where the interger 589 is the first element of the two element tuple of I and Remote_bot
function get_Remote_bot (list, index_to_search)=
switch list index_to_search;;
It's ok.
let get_Remote_bot Remote_bot_List 589 -> remote_bot_object_I_am_looking_for in
(
//I do what I want to do to the remote_bot_object_I_am_looking_for in the following code
It's ok
http://www.scolring.org/files/doc_html/switch.html
Thus, the result of your get_Remote_bot will be a Remote_bot variable or nil if not found (index out of range by example)
Offline
Thx Iri
Offline