The online racing simulator
Quote from Bass-Driver :but somehow it give me an error. i also removed 'await'

The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'.

with await removed:

'Task<List<LFSRestAPI.ModCarEntry>>' does not contain a definition for 'Count' and no extension method 'Count' accepting a first argument of type 'Task<List<LFSRestAPI.ModCarEntry>>' could be found (are you missing a using directive or an assembly reference?)

but which assembly??

async methods have a return type of Task (that means that the method is not yet processed and code was not run inside it) to run it you have to start and wait for the Task to finish. There's a specific keyword for that: await. But it can only be used if the method ytou're calling it from is also marked as async.
Since your code is not async:
public void getmoddedcarinfo

There's a method for that: .Wait() that halts the caller thread until the task is completed.

So in your case - first you have a Task after calling the GetModdedCars

var listTask = LFSRestAPI.GetModdedCars(newCfg.varsLapper.RestAPIClientID, newCfg.varsLapper.RestAPIClientSecret);

now the variable listTask is of type Task<List<ModCarEntry>>.
next you have to start and wait for listTask to finish:

var list = listTask.Wait();

By doing so it returns (sets it to list variable) the underlying List<ModCarEntry>

only then you can use .Count on the list.

so to put it to a single line:

var cnt = LFSRestAPI.GetModdedCars(...).Wait().Count

hope that clears it up somewhat
hello,i've good news, got it working.

First i tried xspeedasx his code with his explaination about .Wait() and .Count
but that didnt do anything, which result is more Task related errors.

Then i googled how to call an async task function in C#.
I came across this page: https://stackoverflow.com/ques ... askt-method-synchronously

In one of the posts it say to use

// For Task<T>: will block until the task is completed...
var result = task.Result;

Basically what xspeedasx was explaining with .Wait().
Then i used LakynVonLegendaus his bit of code from previous post to display some info.

This is the code:


<?php 
public void getmoddedcarinfo(GLScript.unionVal valArrayList args)
        {
            
infoPlayer currInfoPlayer newCfg.getCurrInfoPlayer();
            
string ident val.nameFunction;

            var 
CarInfo LFSRestAPI.GetModdedCars(newCfg.varsLapper.RestAPIClientIDnewCfg.varsLapper.RestAPIClientSecret).Result;
            for (
int i 0CarInfo.Counti++)
            {
                
Console.WriteLine(CarInfo[i].id " = " CarInfo[i].name);
            }
        }
?>

Attached images
REALLYYYY.PNG
ok now spending hours with the following issue.
trying to retrieve the info of 1 single car.

But after Deserializing the response from the API i get NULL.
I know it has something todo with setting up the classes, but i cannot figure out what i'm doing wrong here.

Websites i used to setup the classes.
https://json2csharp.com/

Here is some info:
Data i receive:


<?php 
{"data":{"id":"1AF20E","name":"TOMMY28","descriptionShort":"Tommy 28 - A vintage racing car from 1920'","description":"feel the vintage racing with big moustache and reckless drivers\r\ndo not search extrem grip, do not search evil power, but be extremely sharp in your track feeling with this 1928 Tommy racing car.\r\n\r\n2 configs :\r\n- Sport : stricly minimum to race\r\n- Sport Lux : tiny windscreen and lights (very usefull when LFS release the night races)\r\n\r\nMartin18 has work on the 8 inline engine !\r\nFlame CZE give me authorisation for his Hadraplan's steering wheel, clocks and mirrors (modified)\r\nNene87 help me on editor and blender at the beginning\r\n\r\nClocks are old but it works.\r\nsee the motor behind events ;)\r\nlook at the hand-polishing chromes !\r\n2 versions\r\n\r\nantiroll bar are finally added to maintain fun to drive (it was very slippery without)\r\n\r\n- skins with racing numbers and vintage look\r\n- suspensions 3d anim on the rear\r\n- lean driver animation","userId":79595,"userName":"Tomfuel","wip":true,"publishedAt":1640879379,"numDownloads":3803,"curUsage":0,"rating":4.34,"numRatings":43,"staffPick":false,"tweakMod":false,"version":5,"lastDownloadedAt":1640881808,"class":2,"ev":false,"coverUrl":"https:\/\/www.lfs.net\/attachment\/276798","screenshotUrls":["https:\/\/www.lfs.net\/attachment\/274160","https:\/\/www.lfs.net\/attachment\/274161","https:\/\/www.lfs.net\/attachment\/274162","https:\/\/www.lfs.net\/attachment\/274163","https:\/\/www.lfs.net\/attachment\/274164","https:\/\/www.lfs.net\/attachment\/274165","https:\/\/www.lfs.net\/attachment\/274166","https:\/\/www.lfs.net\/attachment\/274167"],"vehicle":{"iceCc":5237,"iceNumCylinders":8,"iceLayout":0,"evRedLine":0,"drive":1,"shiftType":1,"power":81.76211547851562,"maxPowerRpm":3586,"torque":233.3720703125,"maxTorqueRpm":1687,"mass":889.9309692382812,"bhp":109.66752549133301,"powerWeightRatio":91.87467152480184,"bhpTon":125.20896003186276,"fuelTankSize":39.000003814697266}}}
?>

The Classes i've set up

public class GetCarInfo
{
public ModCarEntry CarInfo { get; set; }
}

public class ModCarEntry
{
public string id { get; set; }
public string name { get; set; }
public string descriptionShort { get; set; }
public string description { get; set; }
public int userId { get; set; }
public string userName { get; set; }
public bool wip { get; set; }
public int publishedAt { get; set; }
public int numDownloads { get; set; }
public int curUsage { get; set; }
public double rating { get; set; }
public int numRatings { get; set; }
public int version { get; set; }
public int lastDownloadedAt { get; set; }
public int _class { get; set; }
public bool ev { get; set; }
public string coverUrl { get; set; }
public List<string> screenshotUrls { get; set; }

public CarDetails details { get; set; }
}
public class CarDetails
{
public int iceCc { get; set; }
public int iceNumCylinders { get; set; }
public int iceLayout { get; set; }
public int evRedLine { get; set; }
public int drive { get; set; }
public int shiftType { get; set; }
public double power { get; set; }
public int maxPowerRpm { get; set; }
public double torque { get; set; }
public int maxTorqueRpm { get; set; }
public double mass { get; set; }
public double bhp { get; set; }
public double powerWeightRatio { get; set; }
public double bhpTon { get; set; }
public double fuelTankSize { get; set; }
}

Not really sure where this fits in with the rest, but the root of your JSON object is "data" not "CarInfo"
i'm so ****** stupid. def looking at the wrong stuff :SSchwitzFace -> palm


Thanks, it is working

Now i can get info of 1 single mod and i can the entire list of mods under 1 single command.
now its time to build a script around that.

Still need to add more info to the code to make the script properly working.


Thank you everyone.
Today, i've been figuring out how to convert the decimal date number to a readable date/time format.
and created some code that is usable in the LFSLapper scripts.


<?php 
###example###
$userName GetCurrentPlayerVar("UserName");
/*Request modinfo (31 variables)*/
$modinfo getmoddedcarinfo($userName);

/*Display modinfo */
privmsg("Car ID(SkinID) : ".$carinfo["id"]);
privmsg("CarName : ".$carinfo["name"]);
privmsg("DescShort : ".$carinfo["descriptionshort"]);
privmsg("Desc : ".$carinfo["description"]);
?>

created an testscript to display some of the mod information.

Attached images
modinfo.PNG
New Testversion available : Testversion #6
Download in first post.

+---------------------------------------------------------------+
|Changes in 7.0.9.0 TEST #6
+---------------------------------------------------------------+
=================================================
New:
=================================================

1: LFSRestAPI to request information about certain mod
-Register your LFSLapper @ https://www.lfs.net/account/api
-Fill in your ClientID and ClientSecret in myInc.LPR (includes/myinc.lpr)
-2 differend ways to request modinfo , by username(must be OnTrack!!!) or by SkinID

$modinfo = getmoddedcarinfo("Bass-Driver");
or
$modinfo = getmoddedcarinfo("E25059");

-Variables in testscript below or in (includes/optional/lfsrestapi_Info.lpr)

Attached files
lfsrestapi_Info.txt - 7.6 KB - 172 views
2
This thread is closed

FGED GREDG RDFGDR GSFDG