Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline alisin  
#1 Posted : 19 January 2023 02:57:31(UTC)
alisin

Rank: Newbie

Groups: Registered
Joined: 19/01/2023(UTC)
Posts: 6
Location: Canada

Hello!

Brand new to SMath, and I was curious to know if there was a way to simulate creating objects with properties etc. For example, I have a car object that has a speed it's moving at and its weight.
Offline Razonar  
#2 Posted : 19 January 2023 03:35:14(UTC)
Razonar


Rank: Advanced Member

Groups: Registered
Joined: 28/08/2014(UTC)
Posts: 1,068
Uruguay

Was thanked: 603 time(s) in 383 post(s)
Hi. Something like this?

obj_set_get.sm (12kb) downloaded 29 time(s).

Best regards
Alvaro.
thanks 2 users thanked Razonar for this useful post.
on 19/01/2023(UTC),  on 20/01/2023(UTC)
Offline alisin  
#3 Posted : 19 January 2023 03:43:15(UTC)
alisin

Rank: Newbie

Groups: Registered
Joined: 19/01/2023(UTC)
Posts: 6
Location: Canada

Hey Alvaro, that is really cool, I didn't know you could do that in SMath. Thank youClap
Offline alisin  
#4 Posted : 19 January 2023 21:33:01(UTC)
alisin

Rank: Newbie

Groups: Registered
Joined: 19/01/2023(UTC)
Posts: 6
Location: Canada

Hey Alvaro,

I was testing out your methods with the inclusion of loops and it seems that I can't create a variable beforehand and assign it, it has to be empty. Do you know a way around this?
Screenshot 2023-01-19 102955.png


This is ultimately what I am trying to do with these functions, where I can get a mutable array of "Zones", each with their own properties (ie. area, x/y location etc.)
Screenshot 2.png


For reference I read through this thread as well: https://en.smath.com/for...iable-Name--str2var.aspx
and tried some of the solutions posted on there but to no avail.
Offline alisin  
#5 Posted : 19 January 2023 22:28:07(UTC)
alisin

Rank: Newbie

Groups: Registered
Joined: 19/01/2023(UTC)
Posts: 6
Location: Canada

I figured it out, just don't know a way around it. Since I'm calling str2num(output_i), it's giving me the value of that expression and not the variable itself.
Offline Razonar  
#6 Posted : 19 January 2023 23:22:47(UTC)
Razonar


Rank: Advanced Member

Groups: Registered
Joined: 28/08/2014(UTC)
Posts: 1,068
Uruguay

Was thanked: 603 time(s) in 383 post(s)
Originally Posted by: alisin Go to Quoted Post
I figured it out, just don't know a way around it. Since I'm calling str2num(output_i), it's giving me the value of that expression and not the variable itself.


Yep. You need to call str2num at the worksheet level. Something like this

Clipboard01.png

obj_set_get.sm (19kb) downloaded 4 time(s).

Also, I'm go to modify the code for accept set or collections.

Best regards.
Alvaro.

Offline overlord  
#7 Posted : 20 January 2023 03:32:59(UTC)
overlord


Rank: Advanced Member

Groups: Registered
Joined: 23/07/2013(UTC)
Posts: 900
Turkey

Was thanked: 359 time(s) in 240 post(s)
Jean's reply is not corresponding with question.

This algorithm is not creating an object.
It is only finding index of a key in data.
thanks 2 users thanked overlord for this useful post.
on 20/01/2023(UTC),  on 20/01/2023(UTC)
Offline Razonar  
#8 Posted : 20 January 2023 04:08:17(UTC)
Razonar


Rank: Advanced Member

Groups: Registered
Joined: 28/08/2014(UTC)
Posts: 1,068
Uruguay

Was thanked: 603 time(s) in 383 post(s)
Originally Posted by: overlord Go to Quoted Post
Jean's reply is not corresponding with question.


Thanks.

Updated.

obj_set_get V2.sm (47kb) downloaded 14 time(s).
obj_set_get V2.pdf (155kb) downloaded 11 time(s).

Best regards.
Alvaro.

thanks 2 users thanked Razonar for this useful post.
on 20/01/2023(UTC),  on 20/01/2023(UTC)
Offline alisin  
#9 Posted : 20 January 2023 19:57:13(UTC)
alisin

Rank: Newbie

Groups: Registered
Joined: 19/01/2023(UTC)
Posts: 6
Location: Canada

Originally Posted by: Razonar Go to Quoted Post
Originally Posted by: overlord Go to Quoted Post
Jean's reply is not corresponding with question.


Thanks.

Updated.

obj_set_get V2.sm (47kb) downloaded 14 time(s).
obj_set_get V2.pdf (155kb) downloaded 11 time(s).

Best regards.
Alvaro.



This is incredible work, it would be really cool to see this kind of feature built-in to SMath in the future.
Offline Davide Carpi  
#10 Posted : 20 January 2023 23:30:40(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,532
Man
Italy
Location: Italy

Was thanked: 1269 time(s) in 834 post(s)
Originally Posted by: overlord Go to Quoted Post
Jean's reply is not corresponding with question.

This algorithm is not creating an object.
It is only finding index of a key in data.


mod: Deleted since it was off-topic.

@Jean: please stay on topic.
If you like my plugins please consider a donation to SMath Studio; for personal contributions to me: paypal.me/dcprojects
Offline alisin  
#11 Posted : 21 January 2023 03:50:59(UTC)
alisin

Rank: Newbie

Groups: Registered
Joined: 19/01/2023(UTC)
Posts: 6
Location: Canada

Originally Posted by: Razonar Go to Quoted Post
Originally Posted by: overlord Go to Quoted Post
Jean's reply is not corresponding with question.


Thanks.

Updated.

obj_set_get V2.sm (47kb) downloaded 14 time(s).
obj_set_get V2.pdf (155kb) downloaded 11 time(s).

Best regards.
Alvaro.



I"ve been absolutely loving using this! Is there a way to disable the historical value saving? I'm trying to override some values rather than keep a record of them, I was thinking of going through a loop that check to see if the second column is zero and making a new submatrix without that row and calling it recursively until there are no 0 values left, however that presents a future problem when the value I want to set is 0. Is there a way around this?
Offline Razonar  
#12 Posted : 21 January 2023 05:32:36(UTC)
Razonar


Rank: Advanced Member

Groups: Registered
Joined: 28/08/2014(UTC)
Posts: 1,068
Uruguay

Was thanked: 603 time(s) in 383 post(s)
Originally Posted by: alisin Go to Quoted Post
... Is there a way to disable the historical value saving? ...


Hi. A version without values history.

obj_set_get V3.sm (54kb) downloaded 8 time(s).

Best regards.
Alvaro.

Offline uni  
#13 Posted : 21 January 2023 09:23:13(UTC)
uni


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 10/11/2010(UTC)
Posts: 1,343
Man
Russian Federation

Was thanked: 1174 time(s) in 676 post(s)
Maybe this plugin will be useful: Wiz Functions

It contains a set of functions for manipulating key and value pairs.
Russia ☭ forever
Viacheslav N. Mezentsev
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.