geting an random intiger in a sentance and adding it to a variable
Author |
Message |
pozaj0206
|
Posted: Fri Sep 02, 2011 9:00 pm Post subject: geting an random intiger in a sentance and adding it to a variable |
|
|
What is it you are trying to achieve?
I have a file the looks like...
biomeSize:1.5
minMoisture:0.0
maxMoisture:1.0
ECT.
I want to make turing open this file ad get the 1.5 in a variable ad the 0.0 in another 1 ect.
What is the problem you are having?
the 1.5 ad the 0.0 ad whatever else are variable they could be any number when the file is loaded.
Describe what you have tried to solve this problem
I dot know how to approach this problem.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
this is how it wrights to the file
Turing: |
procedure Save
open : stream, "XXXXXXXXXXXXXXXXXXXX.ini", put
%wrighting the settigs to the file%
put : stream, "<Biome Mod - All Biome Variables>"
put : stream, "biomeSize:", item1
put : stream, "minMoisture:", item2
put : stream, "maxMoisture:", item3
|
Please specify what version of Turing you are using
4.1 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Fri Sep 02, 2011 9:57 pm Post subject: RE:geting an random intiger in a sentance and adding it to a variable |
|
|
Do you absolutely have to include 'biomeSize' and 'minMoisture', etc in the input file? You could just have
1.5
0.0
1.0
in the input file and it'd work fine. |
|
|
|
|
![](images/spacer.gif) |
pozaj0206
|
Posted: Sat Sep 03, 2011 9:04 am Post subject: Re: RE:geting an random intiger in a sentance and adding it to a variable |
|
|
Insectoid @ Fri Sep 02, 2011 9:57 pm wrote: Do you absolutely have to include 'biomeSize' and 'minMoisture', etc in the input file? You could just have
1.5
0.0
1.0
in the input file and it'd work fine.
yes I do because it is a config file for another program ad there is about 350 of these all with different names |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Sat Sep 03, 2011 9:46 am Post subject: RE:geting an random intiger in a sentance and adding it to a variable |
|
|
you can either read one character at a time, and figure things out as you go along, or read the entire line, find colon (with something like index), and split the line into usable parts. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
pozaj0206
|
Posted: Sat Sep 03, 2011 10:30 am Post subject: Re: RE:geting an random intiger in a sentance and adding it to a variable |
|
|
Tony @ Sat Sep 03, 2011 9:46 am wrote: you can either read one character at a time, and figure things out as you go along, or read the entire line, find colon (with something like index), and split the line into usable parts.
Ok ill try that thx ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
pozaj0206
|
Posted: Sat Sep 03, 2011 10:55 am Post subject: Re: RE:geting an random intiger in a sentance and adding it to a variable |
|
|
Tony @ Sat Sep 03, 2011 9:46 am wrote: you can either read one character at a time, and figure things out as you go along, or read the entire line, find colon (with something like index), and split the line into usable parts.
actually would there be a way for turing to like go to line 1 then right XXX times until it passes the colon the get the numbers and decimal until end of the config line?
(it doesn't matter to me if i have like 10 lines of code for every entry in the config file) |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Sat Sep 03, 2011 11:34 am Post subject: RE:geting an random intiger in a sentance and adding it to a variable |
|
|
Quote: it doesn't matter to me if i have like 10 lines of code for every entry in the config file
This is bad. Never say this again. You'll learn bad habits while you give yourself carpel tunnel from typing hundreds of thousands of lines for every program.
You know what a function is, right? Write a function that takes a string as input and outputs an integer. This is probably the easiest way to do it. |
|
|
|
|
![](images/spacer.gif) |
pozaj0206
|
Posted: Sun Sep 04, 2011 12:08 am Post subject: Re: geting an random intiger in a sentance and adding it to a variable |
|
|
Thanks Insectoid, i never thought about using a function.
ill post how it went later cuz Indiana Jones is on right now :p
+15 bits for you :p |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|
|