Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, dr_panther), 1,282 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
[Solved] Pointing to variables #245234
01/09/09 00:16
01/09/09 00:16
Joined: Jul 2008
Posts: 54
Taipei, Taiwan
PlaystationThree Offline OP
Junior Member
PlaystationThree  Offline OP
Junior Member

Joined: Jul 2008
Posts: 54
Taipei, Taiwan
This is kinda hard to explain in 3dgs terms because its from Adobe Flash's actionscript.

Let's say I have a fer variables: var1 var2 var3.

Say I want to go through all of them in sequence, setting each to a certain value. In actionscript I would do:

Code:
function goThrough(number){
    var i = 1;
    while(i<=number){
        ["var"+i] = random(10);
    }
}
goThrough(3);
 


while in lite-c you would have to:

Code:
   ...
    var1 = random(10);
    var2 = random(10);
    var3 = random(10);
   ...
 


Essencially what it does is go through all the vars and sets each to a random number. What the ["var"+i] section does is search for the variable "varX" where X is whatever i is. So if i == 2 then it searches for var2. Can you do something like that in lite-c? I read the sections in the manual about variables but nothing...

Last edited by PlaystationThree; 01/09/09 08:14.

Bet you don't know where Taiwan is lol.

"The Lord is my light and my salvation..." Psm 27:1
Re: Pointing to variables [Re: PlaystationThree] #245238
01/09/09 00:44
01/09/09 00:44
Joined: Oct 2008
Posts: 218
Nashua NH
heinekenbottle Offline
Member
heinekenbottle  Offline
Member

Joined: Oct 2008
Posts: 218
Nashua NH
An array might work.
Code:
function goThrough(var number)
{
	var myArray[128];
	var i;
	for(i = 0; i < number; i++)
	{
		myArray[i] = random(10);
		diag_var("myArray: %f\n",myArray[i]);
		wait(1);
	}
}


EDIT: My code had some C++ syntax that Lite-C did not like.

Last edited by heinekenbottle; 01/09/09 00:53.

I was once Anonymous_Alcoholic.

Code Breakpoint;
Re: Pointing to variables [Re: heinekenbottle] #245240
01/09/09 00:48
01/09/09 00:48
Joined: Jul 2008
Posts: 54
Taipei, Taiwan
PlaystationThree Offline OP
Junior Member
PlaystationThree  Offline OP
Junior Member

Joined: Jul 2008
Posts: 54
Taipei, Taiwan
Good point, but actually what i'm doing is going through a set of TEXT* structs and changing their strings. I guess I should have made that clear in my first post. Sorry.


Bet you don't know where Taiwan is lol.

"The Lord is my light and my salvation..." Psm 27:1
Re: Pointing to variables [Re: PlaystationThree] #245257
01/09/09 03:59
01/09/09 03:59
Joined: Jul 2004
Posts: 1,710
MMike Offline
Serious User
MMike  Offline
Serious User

Joined: Jul 2004
Posts: 1,710
well i love action script to anf the fact in can merge strings just like
var name= "you" + " second" + bla ba and it will result in the complete sentense.

but lite c can't work like that.. as i know..

Re: Pointing to variables [Re: MMike] #245265
01/09/09 05:57
01/09/09 05:57
Joined: Jul 2008
Posts: 54
Taipei, Taiwan
PlaystationThree Offline OP
Junior Member
PlaystationThree  Offline OP
Junior Member

Joined: Jul 2008
Posts: 54
Taipei, Taiwan
Yeah, I would have stuck with Flash because the script system is great, but it doesn't have 3d built in. The 3rd party API suck too.


Bet you don't know where Taiwan is lol.

"The Lord is my light and my salvation..." Psm 27:1
Re: Pointing to variables [Re: PlaystationThree] #245278
01/09/09 07:45
01/09/09 07:45
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline
Serious User
pegamode  Offline
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
If you'd like to store pointers you could use my GSHashmap. You find it under contributions. With this hashmap you can store any pointer under a certain key and get it back. The key is a string that you could build by adding a number to a prefix in a loop as you would do it in flash.

Regards,
Pegamode

Re: Pointing to variables [Re: pegamode] #245281
01/09/09 08:14
01/09/09 08:14
Joined: Jul 2008
Posts: 54
Taipei, Taiwan
PlaystationThree Offline OP
Junior Member
PlaystationThree  Offline OP
Junior Member

Joined: Jul 2008
Posts: 54
Taipei, Taiwan
@pegamode
That sounds what i'm looking for. Thanks for the post, and great contribution.


Bet you don't know where Taiwan is lol.

"The Lord is my light and my salvation..." Psm 27:1
Re: Pointing to variables [Re: PlaystationThree] #245283
01/09/09 08:19
01/09/09 08:19
Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Tobias Offline

Moderator
Tobias  Offline

Moderator

Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Why use an external plugin when the language already offers what you need? I think the C/C++ method of arrays is far better than actionscript, it's much faster and more logical.

Use an array just as heinekenbottle suggests, only without the superflous wait(). When you need TEXT* well then use an array of TEXT*.

Code:
TEXT* texts[128];

function goThrough(var number)
{
	var i;
	for(i = 0; i < number; i++)
	{
		texts[i] = txt_create(1,0);	
	}
}


Re: Pointing to variables [Re: Tobias] #245286
01/09/09 08:33
01/09/09 08:33
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline
Serious User
pegamode  Offline
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
You can use both to solve this problem ... an array or a hashmap. What to choose depends on your needs. Both have advantages and disadvantages. You have to compare arrays with hashmaps and then you have to decide which one fits better your needs.

Re: Pointing to variables [Re: pegamode] #245303
01/09/09 10:39
01/09/09 10:39
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
you can check var_for_name too.


3333333333

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1