ATTENTION

This FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices.


flexsim.com

Go Back   FlexSim Community Forum > FlexSim Software > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 10-30-2013
LINWEIXU
Guest
 
Posts: n/a
Downloads:
Uploads:
Default some problem about tonum command

code like these:


treenode kkk=tonode(234);
double jjjj=tonum(kkk);
pf(jjjj);
pr();

I do not konw why jjjj=234;because kkk==NULL,jjjj shoud be 0 or some else. the description say use a pointer,but that is not correct.

tonum(thing) Description:Assert type as an arithmetic number. Only serves a real purpose in C++, but is encouraged to use in flexscript to ensure cross-compatibility between flexscript and C++.

You will use this often for returning a pointer to an object or node in a field that should return a number, which applies to all triggers and combobox fields in Flexsim.
  #2  
Old 10-31-2013
Cao Guoquan's Avatar
Cao Guoquan Cao Guoquan is offline
Flexsim User
 
Join Date: Oct 2010
Location: China
Posts: 3
Downloads: 13
Uploads: 0
Thanks: 0
Thanked 4 Times in 1 Post
Rep Power: 0
Cao Guoquan is on a distinguished road
Default

This is because the features of C++ pointer

1.FlexScript: somenode = tonode(address)

2.FlexScript: address = tonum(somenode)

Last edited by Cao Guoquan; 10-31-2013 at 05:09 PM.
  #3  
Old 10-31-2013
Phil BoBo's Avatar
Phil BoBo Phil BoBo is offline
Flexsim Development
 
Join Date: Jan 2008
Posts: 756
Downloads: 109
Uploads: 18
Thanks: 385
Thanked 1,483 Times in 525 Posts
Rep Power: 1174
Phil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond repute
Default

Quote:
Originally Posted by LINWEIXU View Post
because kkk==NULL
kkk isn't NULL. It is 234. You assigned it to 234.

If you do tonode(234) == NULL, you'll find that the result is 0 (false). If you do tonode(234) == 234, the result is 1 (true).

tonode(234) returns 234, not NULL.

Quote:
Originally Posted by LINWEIXU View Post
I do not konw why jjjj=234
A pointer is just a memory address. It is a number. jjjj is 234 because you assigned it to 234. When you set a treenode value, you are setting a number that is the memory address. If you explicitly set it to 234, then it is pointing at memory address 234.

Code:
using namespace std;
class Foo
{
};
int _tmain(int argc, _TCHAR* argv[])
{
	Foo* foo = new Foo();
	cout << foo << endl;
	foo = (Foo*) 9;
	cout << foo << endl;
	system("pause");
	return 0;
}
The above code is valid C++ and it works perfectly fine. Here's the output:

Attached Thumbnails
Click image for larger version
Name:	output.png
Views:	132
Size:	15.7 KB
ID:	2331  
The Following 2 Users Say Thank You to Phil BoBo For This Useful Post:
Steven Hamoen (11-01-2013)


Thread Thread Starter Forum Replies Last Post
Problem with a coordinated task sequence. Could somebody please help spotting the problem? Vadim Fooks Q&A 1 08-27-2012 03:26 PM
family command? zhang xin Q&A 0 01-14-2010 06:33 PM
Command getnextnetnodeoutport Martijn van Oostenbrugge Q&A 0 02-22-2008 05:42 AM
releaseitem command AlanZhang Q&A 3 10-04-2007 10:11 AM


All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.